Parag’s Den

Dedicated to my adored friends…..

CheckBoxList Web Server Control

Posted by paragdongre on November 6, 2007

CheckboxList web server control is the same as Checkbox control. Before reading this article, please read my article on CheckBox Web Server Control. In this article we will see how to use the CheckboxList Web server control

  1. How to assign text and retrieve values from a CheckboxList control?
  2. How to go through all the elements inside a CheckBoxList?
  3. How to find the selected items in a CheckBoxList?
CheckboxList – How to assign a text to and how to retrieve the values?

CheckBoxList is almost equivalent to the Listbox web server control. The following example explains how to declare a CheckboxList web server control and how to assign and retrieve values depending upon the values selected by the user.

<title>CheckboxList Web Server Control – by Das </title><script language=vb runat=server>

Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)

     Dim ctr As Integer
     lblResult.Text = “The values for your selection are: “
     For ctr = 0 To chkBoxList.Items.Count – 1
          If chkBoxList.Items(ctr).Selected Then
               lblResult.Text += chkBoxList.Items(ctr).Value & “, “
          End If

End Sub

<body style=”font: 10pt verdana”>

<form id=”Form1″ method=”post” runat=”server”>

     <asp:Label ID=lblHobby text=”What are your hobbies?” Runat=server />
     <asp:CheckBoxList ID=chkBoxList Runat=server>
     <asp:ListItem Value=1>Music</asp:ListItem>
     <asp:ListItem Value=2>Driving</asp:ListItem>
     <asp:ListItem Value=3>Boating</asp:ListItem>
     <asp:ListItem Value=4>Fishing</asp:ListItem>
     <asp:ListItem Value=5>Eating</asp:ListItem>
     <asp:Button ID=”btnSubmit” Text=”Submit” OnClick=”btnSubmit_Click” Runat=server />
     <asp:Label ID=”lblResult” ForeColor=”#ff0000″ Font-Bold=”True” Runat=server />




Leave a Reply

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

You are commenting using your 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: