我的问题是下一个: 我必须制作一个必须包含测试题的页面 我已经将它用于正常问题,但在下一点,我需要在页脚模板中有一个下拉列表,用户可以从该列表中选择图像名称,文本框获取文件路径。
文件路径如下:
"〜/ Dokuments /" + v_tren_dirnev(每个测试的不同文件夹)+" / Teszt /"
aspx的代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Kerdesek_Valaszok.aspx.cs" Inherits="Kerdesek_Valaszok" %>
<%@ Register Src="UserControl/AutoRedirect.ascx" TagName="AutoRedirect" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
runat="Server">
<uc1:AutoRedirect ID="AutoRedirect1" runat="server" />
<asp:SqlDataSource ID="SqlDSTreningek" runat="server" ConnectionString="<%$ ConnectionStrings:dbcs %>"SelectCommand="SELECT * FROM [trening] WHERE ([tren_deleted] = @tren_deleted)">
<SelectParameters>
<asp:Parameter DefaultValue="false" Name="tren_deleted" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ObjectDataSource ID="odsKerdesek" runat="server" DeleteMethod="DeleteKerdes" InsertMethod="InsertKerdes" SelectMethod="GetAllKerdes" TypeName="trening.KerdesekDataAccessLayer" UpdateMethod="UpdateKerdes">
<SelectParameters>
<asp:Parameter Name="TrenId" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="KerdTrenId" Type="Int32" />
<asp:Parameter Name="KerdKerdes" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
<asp:Parameter Name="KerdKerdes" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsValaszok" runat="server" DeleteMethod="DeleteValasz" InsertMethod="InsertValasz" SelectMethod="GetAllValasz" TypeName="trening.ValaszokDataAccessLayer" UpdateMethod="UpdateValasz">
<SelectParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ValaId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ValaKerdId" Type="Int32" />
<asp:Parameter Name="ValaValasz" Type="String" />
<asp:Parameter Name="ValaHelyes" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ValaId" Type="Int32" />
<asp:Parameter Name="ValaValasz" Type="String" />
<asp:Parameter Name="ValaHelyes" Type="Boolean" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
<table id="kerdesek_valaszok">
<tr>
<td colspan="3">
<h2>Tréning kérdések és válaszok karbantartása</h2>
</td>
</tr>
<tr>
<td colspan="3">
<asp:DropDownList ID="ddlTreningek" runat="server" DataSourceID="SqlDSTreningek" DataTextField="tren_megnevezes" DataValueField="tren_id" Font-Size="Large" AutoPostBack="True" OnDataBound="ddlTreningek_DataBound" OnSelectedIndexChanged="ddlTreningek_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="gvKerdesek" runat="server" AutoGenerateColumns="False" DataKeyNames="kerd_id" DataSourceID="odsKerdesek" CellPadding="4" ShowFooter="True" ForeColor="#333333" GridLines="None" HorizontalAlign="Center" OnRowCommand="gvKerdesek_RowCommand" OnSelectedIndexChanged="gvKerdesek_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="kerd_id" InsertVisible="False" SortExpression="kerd_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("kerd_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("kerd_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="kerd_tren_id" InsertVisible="False" SortExpression="kerd_tren_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("kerd_tren_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("kerd_tren_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Kérdések" SortExpression="kerd_kerdes">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("kerd_kerdes") %>' MaxLength="250" Size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox1" runat="server" ErrorMessage="Kötelező a kérdést megadni!" ValidationGroup="update" ControlToValidate="TextBox1" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("kerd_kerdes") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbNewKerdes" runat="server" MaxLength="250" Size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox2" runat="server" ErrorMessage="Kötelező az új kérdést megadni" ValidationGroup="insert" ControlToValidate="txbNewKerdes" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="btnUpdateKerdes" runat="server" CausesValidation="True" ValidationGroup="update" CommandName="UpdateKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/update.png" Height="25" ToolTip="Módosítás" />
<asp:ImageButton ID="btnCancelKerdes" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="~/App_Themes/Theme1/cancel.png" Height="25" ToolTip="Mégsem" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEditKerdes" runat="server" CausesValidation="false" CommandName="EditKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/edit.png" Height="25" ToolTip="Szerkesztés" />
<asp:ImageButton ID="btnSelectKerdes" runat="server" CausesValidation="false" CommandName="SelectKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/select.png" Height="25" ToolTip="Kiválasztás" />
<asp:ImageButton ID="btnDeleteKerdes" runat="server" CausesValidation="false" CommandName="DeleteKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/delete.png" Height="25" ToolTip="Törlés" OnClientClick="return confirm('Biztosan törölni akarja ezt a kérdést és a hozzátartozó válaszokat?');" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnInsertKerdes" CausesValidation="true" ValidationGroup="insert" runat="server" OnClick="btnInsertKerdes_Click" ImageUrl="~/App_Themes/Theme1/insert.png" Height="25" ToolTip="Új kérdés rögzítése" />
<!--AG dropdown list -->
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FF9900" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br />
<asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="insert" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary2" ValidationGroup="update" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary3" ValidationGroup="insertValasz" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary4" ValidationGroup="updateValasz" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
</td>
</tr>
<tr>
<td colspan="3">
<br />
<asp:GridView ID="gvValaszok" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="vala_id" DataSourceID="odsValaszok" ShowFooter="True" ForeColor="#333333" GridLines="None" EmptyDataText="Nincsenek még válaszok megadva!" HorizontalAlign="Center" OnRowCommand="gvValaszok_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="vala_id" InsertVisible="False" SortExpression="vala_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("vala_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("vala_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="vala_kerd_id" SortExpression="vala_kerd_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("vala_kerd_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("vala_kerd_id") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblNewValaKerdId" runat="server" Text='<%# Bind("vala_kerd_id") %>'></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Válaszok" SortExpression="vala_valasz">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("vala_valasz") %>' MaxLength="250" size="100"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("vala_valasz") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbNewValasz" runat="server" MaxLength="250" size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox3" runat="server" ErrorMessage="Kötelező az új választ megadni" ValidationGroup="insertValasz" ControlToValidate="txbNewValasz" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Helyes-e?" SortExpression="vala_helyes">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("vala_helyes") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("vala_helyes") %>' Enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="cbxNewHelyes" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="btnUpdateValasz" runat="server" CausesValidation="True" CommandName="UpdateValasz" CommandArgument='<%# Eval("vala_id") %>' ImageUrl="~/App_Themes/Theme1/update.png" Height="25" ToolTip="Módosítás" />
<asp:ImageButton ID="btnCancelValasz" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="~/App_Themes/Theme1/cancel.png" Height="25" ToolTip="Mégsem" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEditValasz" runat="server" CausesValidation="false" CommandName="Edit" ImageUrl="~/App_Themes/Theme1/edit.png" Height="25" ToolTip="Szerkesztés" />
<asp:ImageButton ID="btnDeleteValasz" runat="server" CausesValidation="false" CommandName="DeleteValasz" CommandArgument='<%# Eval("vala_id") %>' ImageUrl="~/App_Themes/Theme1/delete.png" Height="25" ToolTip="Törlés" OnClientClick="return confirm('Biztosan törölni akarja ezt a választ?');" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnInsertValasz" CausesValidation="true" ValidationGroup="insertValasz" runat="server" OnClick="btnInsertValasz_Click" ImageUrl="~/App_Themes/Theme1/insert.png" Height="25" ToolTip="Új kérdés rögzítése" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</td>
</tr>
</table>
这背后的代码:
public partial class Kerdesek_Valaszok : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnInsertKerdes_Click(object sender, EventArgs e)
{
odsKerdesek.InsertParameters["KerdTrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.InsertParameters["KerdKerdes"].DefaultValue = ((TextBox)gvKerdesek.FooterRow.FindControl("txbNewKerdes")).Text;
odsKerdesek.Insert();
gvKerdesek.DataBind();
}
protected void btnInsertValasz_Click(object sender, EventArgs e)
{
if (gvKerdesek.SelectedRow != null)
{
odsValaszok.InsertParameters["ValaKerdId"].DefaultValue = ((Label)gvValaszok.Rows[0].FindControl("Label3")).Text;
odsValaszok.InsertParameters["ValaValasz"].DefaultValue = ((TextBox)gvValaszok.FooterRow.FindControl("txbNewValasz")).Text;
odsValaszok.InsertParameters["ValaHelyes"].DefaultValue = ((CheckBox)gvValaszok.FooterRow.FindControl("cbxNewHelyes")).Checked.ToString();
odsValaszok.Insert();
gvValaszok.DataBind();
} else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Nincs a kérdés kiválasztva!');", true);
}
}
protected void ddlTreningek_DataBound(object sender, EventArgs e)
{
odsKerdesek.SelectParameters["TrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.Select();
}
protected void ddlTreningek_SelectedIndexChanged(object sender, EventArgs e)
{
odsKerdesek.SelectParameters["TrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.Select();
gvKerdesek.SelectRow(-1);
}
protected void gvKerdesek_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "SelectKerdes")
{
string tmp = e.CommandArgument.ToString();
int selind = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
odsValaszok.SelectParameters["KerdId"].DefaultValue = e.CommandArgument.ToString();
odsValaszok.Select();
gvKerdesek.SelectedIndex = selind;
gvKerdesek.DataBind();
} else if (e.CommandName == "DeleteKerdes")
{
KerdesekDataAccessLayer.DeleteKerdes(Convert.ToInt32(e.CommandArgument));
gvKerdesek.DataBind();
} else if (e.CommandName == "EditKerdes")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
gvKerdesek.EditIndex = rowindex;
gvKerdesek.DataBind();
} else if (e.CommandName == "UpdateKerdes")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int kerd_id = Convert.ToInt32(e.CommandArgument);
odsKerdesek.UpdateParameters["KerdId"].DefaultValue = ((Label)gvKerdesek.Rows[rowindex].FindControl("Label1")).Text;
odsKerdesek.UpdateParameters["KerdKerdes"].DefaultValue = ((TextBox)gvKerdesek.Rows[rowindex].FindControl("TextBox1")).Text;
odsKerdesek.Update();
gvKerdesek.EditIndex = -1;
gvKerdesek.DataBind();
}
}
protected void gvValaszok_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteValasz")
{
ValaszokDataAccessLayer.DeleteValasz(Convert.ToInt32(e.CommandArgument));
gvValaszok.DataBind();
} else if (e.CommandName == "UpdateValasz")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int vala_id = Convert.ToInt32(e.CommandArgument);
odsValaszok.UpdateParameters["ValaId"].DefaultValue = ((Label)gvValaszok.Rows[rowindex].FindControl("Label1")).Text;
odsValaszok.UpdateParameters["ValaValasz"].DefaultValue = ((TextBox)gvValaszok.Rows[rowindex].FindControl("TextBox1")).Text;
odsValaszok.UpdateParameters["ValaHelyes"].DefaultValue = ((CheckBox)gvValaszok.Rows[rowindex].FindControl("CheckBox1")).Checked.ToString();
odsValaszok.Update();
gvValaszok.EditIndex = -1;
gvValaszok.DataBind();
}
}
}
答案 0 :(得分:0)
正如我之前所说,问题出在下面。这是外观和asp代码的图像。我提出了一个替代解决方案,但我也确实想要这个。
The image
为此,我需要一个代码:
下拉列表必须包含一个文件夹文件名,在我选择其中一个文件名之后,左侧的文本框将被填充为如下所示的文件路径:
〜/ Dokuments / 10001 / Teszt / Slide01.JPG
可以通过顶部下拉列表更改10001,该列表包含不同的测试名称。如果选择测试,则路径会自动更改,因此这不是问题。
然后,当您从下拉列表中选择默认元素时,就不能仅以一种方式更改文本框的内容。