【发布时间】:2014-04-15 20:42:43
【问题描述】:
我有一个列表视图,我在其中使用了更新面板,所有代码都在更新面板中。我使用了一个复选框和一个事件来检查是否选中了复选框,文本框的可见性应该为真,下拉列表的可见性应该为假。但是在选中复选框后,软件会中断并显示对象引用未设置为对象的实例。错误。我的 asp.net 代码:
<EditItemTemplate>
<asp:UpdatePanel ID="upchk" runat="server" UpdateMode="Conditional">
<ContentTemplate>
///
<td><asp:Label ID="label17" CssClass="fasele" runat="server" Text="رشته : ">
</asp:Label></td>
<td><asp:DropDownList ID="DropDownList2" DataSourceID="SqlDataSource1"
DataTextField="reshte" DataValueField="reshteId" AutoPostBack="True"
runat="server" ></asp:DropDownList></td>
<td>
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server"
oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true"
EnableViewState="true" /> : افزودن رشته جدید</td>
/////
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger EventName="checkedchanged" ControlID="CheckBox1" />
</Triggers>
</asp:UpdatePanel>
</EditItemTemplate>
我的 .cs 代码:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)ListView1.FindControl("CheckBox1");
TextBox txtrshte = (TextBox)ListView1.FindControl("TextBox8");
DropDownList drpreshte = (DropDownList)ListView1.FindControl("DropDownList2");
if (chk.Checked)
{
txtrshte.Visible = true;
drpreshte.Visible = false;
}
}
【问题讨论】:
-
您可能想查看this 问题及其答案