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" />
Advertisement
