当FormView OnModeChangingEVent触发时,我想根据天气启用/禁用文本框,选中或不选中复选框。 但是,当我单击编辑按钮OnModeChanging事件触发并且下面显示的代码被激活但模式更改后结果不显示(即选中Checkbox1时未禁用文本框1)。任何人都可以帮助我吗?
<asp:formview ID="FormView1" OnModeChanging="FormView1_ModeChanging" runat="server">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" />
</InsertItemTemplate>
</asp:formview>
protected void FormView1_ModeChanging(object sender, FormViewModeEventArgs e)
{
switch (e.NewMode)
{
case FormViewMode.Edit:
TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");
CheckBox CheckBox1 = (CheckBox)FormView1.FindControl("CheckBox1");
if (CheckBox1.Checked)
{
TextBox1.Enabled = false;
}
else
{
TextBox1.Enabled = true;
}
break;
}
}