我在一个formview中有一个面板,当我选中一个复选框(也在formview中)时,该面板应该可见。我能够访问控件,但我不知道如何实际使它工作。到目前为止,这是我的代码隐藏,我知道它不对,但它给出了我正在尝试做的基本概念。
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
Dim checkGenEd As CheckBox = FormView1.FindControl("checkGenEd")
Dim panelOutcome As Panel = FormView1.FindControl("panelOutcome")
If checkGenEd.Checked = True Then
panelOutcome.Visible = True
Else
panelOutcome.Visible = False
End If
End If
End Sub
答案 0 :(得分:0)
问题有点不清楚,但如果你想要选中/取消选中复选框,那么你需要使用复选框的OnCheckChanged事件:
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="checkGenEd" AutoPostBack="true" Checked='<%# Eval("YourDBField") %>' OnCheckedChanged="checkGenEd_CheckedChanged" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Protected Sub checkGenEd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim checkGenEd As CheckBox = DirectCast(sender, CheckBox)
Dim panelOutcome As Panel = FormView1.FindControl("panelOutcome")
If checkGenEd.Checked = True Then
panelOutcome.Visible = True
Else
panelOutcome.Visible = False
End If
End Sub