Display CheckBoxList Selections


I was needing to do a CheckBoxList that would talley up the results, and show a graphic if nothing was checked, and hide the graphic if something was checked. I found the following somewhere and tweaked it a little:

  Sub Check(ByVal sender As Object, ByVal e As EventArgs)
        Dim i As Object

        Label4.Text = "<p>Selected Item(s):</p>"

        For i = 0 To txtCheckBox.Items.Count - 1

            If txtCheckBox.Items(i).Selected Then
                Image6.Visible = False
                Label4.Text += txtCheckBox.Items(i).Text + "<br />"
            ElseIf i = 0 Then
                Image6.Visible = True
            End If

        Next
    End Sub

     <asp:CheckBoxList ID="txtCheckBox" runat="server" TextAlign="left" AutoPostBack="True" OnSelectedIndexChanged="Check">
                        <asp:ListItem Text="One" />
                        <asp:ListItem Text="Two" />
                        <asp:ListItem Text="Three" />
                        <asp:ListItem Text="Four" />
       </asp:CheckBoxList>
                 
                    <asp:Label ID="Label4" runat="server" Text=""></asp:Label>
                    <asp:Image ID="Image6" runat="server" Visible="True" ImageUrl="img/ValidateWarning.png" />
Advertisements

~ by worldcrossings on July 26, 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: