Tags Posts tagged with "how to use checkboxlist control in asp.net"

how to use checkboxlist control in asp.net

0 443
how to use checkboxlist control in asp.net

What is CheckBoxList Control and how to use it in ASP.NET

CheckBoxList is a Standard Control which resides in toolbox in Visual Studio (VS) Studio Framework. In this article i will describe that what is CheckBoxList control and how to use it in ASP.NET.  To insert this control in your web form simply double click on it or drag it to the web form. When you insert it in your web form then the following coding appears in the source page of the web form.

 

 

In the above coding you may change the ID of the control as per your requirement. Now the next step is to insert items in this CheckBoxList. To insert items in CheckBoxList you have to type the following coding. Also watch the following video for more details…

 

 

 

You may see that there are 2 attributes namely Text and Value. Text attribute is used for caption purpose i.e. it provides the text appearance to the item. On the other hand Value attribute is used to provide a unique identifier to each item so that it can be accessed in programming using this value. Value attribute is provided in Positive Integer (Natural Number) format only.

Properties of CheckBoxList

  1. RepeatDirection:

This property is used to give horizontal or vertical view to CheckBoxList. This property has 2 values namely Horizontal and Vertical. Consider the following coding and run it in your VS framework…

 

 

In above coding change RepeatDirection values and consider the change.

  1. RepeatColumn

This property is used to show CheckBoxList in Columns. Suppose you want to show CheckBoxList in 2 or 3 columns as per your need then you may set the value of RepeatColumn property to an integer value like 2 or 3. Consider the following coding and run it.

 

 

Above coding will produce 2 columns CheckBoxList. To produce 3 columns CheckBoxList you may set RepeatColumn value to 3 end so on.

  1. RepeatLayout

This property has 2 values namely Flow and Table. When Flow layout is used then items of CheckBoxList shown in a flow means there is no alignment among them, while in Table layout the items of CheckBoxList are shown in the table view. Each item is shown in a column and a row with proper alignment. You may change between both layouts and can feel the change.

 

  1. TextAlign

This property is used for alignment. It has 2 values namely Left and Right. Run the following coding and feel the change.

 

 

  1. AutoPostBack

When this property is set to true then on clicking (check or uncheck) the CheckBoxList control, page postback to server. Postback to server means that the request goes to server to reload the page. This property is set to true when we require to perform any task on clicking the checkbox control and for this we can use SelectedIndexChanged Event to handle this task.

     6. SelectedIndexChanged Event

SelectedIndexChanged event is used to handle any task when someone clicks on the CheckBoxList item. To create SelectedIndexChanged event just go to the property of the CheckBoxList and click in the SelectedIndexChanged textbox and press enter. On pressing enter an event with the default name will be generated. If you want to give any name to this event then type the name of the event and then press enter. Just watch the following video to understand this….

 

 

That is all about CheckBoxList for now. But we will return with more logic about this control very soon. till then happy coding… 🙂

Follow us