Checkboxlist is used to provide a list of checkboxes that can be created dynamically by binding it to the data source.Checkbox is used to select a single value while checkboxlist is used to get a group of information from the user.
How t Bind a Checkboxlist to Datasource:
How to Add items Programmatically in CheckBoxLIst:
If you want to add items to checkboxlist programmatically, use the following code.
How t Bind a Checkboxlist to Datasource:
To bind a checkboxlist to datasource first add the checkboxlist control into your page.When the checkboxlist control is added to your page then a smart tag appears which allows you to specify a datasource or add a items manually to the checkboxlist.Also click on Edit Items to open the ListItem collection editor and add items as shown infigure below:
How to Add items Programmatically in CheckBoxLIst:
If you want to add items to checkboxlist programmatically, use the following code.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
cblMulti.Items.Add(new ListItem("Items 1", "Items 1"));
cblMulti.Items.Add(new ListItem("Items 2", "Items 2"));
cblMulti.Items.Add(new ListItem("Items 3", "Items 3"));
}
}
Here in the code cblmulti.Items.Add take the augument of New ListItem whereas ListItem takes two argument first is Text and Second is Value.
wow....! Very nice and useful article. Your way of explanation is beautiful. I learn a lot of things from your article. The stuff you are using that is very useful and helpful.
ReplyDeleteAsp.net Development | C# Development