开发者

ASP.NET/VB: changing visibilty of panel inside formview

I have a panel inside a formview that is supposed to become visible when a checkbox (also inside the formview) is checked. I am able to access the controls, but I'm not sure how to actually make it work. This is my codebehind so far, I know it's not right, but it gives a basic idea of what I'm trying to do.

Protected Sub FormView1_DataBo开发者_StackOverflow社区und(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


The question is a bit unclear but if you want mean when you check / uncheck the checkbox, then you need to use OnCheckChanged event of your checkbox like:

    <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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜