ASP.NET - how to checked checkboxlist - Asked By msakt on 19-Jun-12 02:01 AM

Jitendra Faye replied to msakt on 19-Jun-12 02:04 AM
If you want to select any item in CheckBoxList, then use this code-

CheckBoxList1.SelectedIndex = 1;   (1 is index number to select)
TSN ... replied to msakt on 19-Jun-12 02:11 AM

Hi

 inorder to get the list of selected checkbox list items , you need to just iterate through the loop of checkboxlist items.

Here is the sample..

ArrayList Selectedvalues = new ArrayList();

for (int i = 0; i < chbxList.Items.Count; i++)

{

 if (chbxList.Items[i].Selected)

 {

  Selectedvalues.Add(chbxList.Items[i].Value);

 }

}

DL M replied to msakt on 19-Jun-12 02:18 AM
Hi..

Try below code

 protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    
    string manufSelect = CheckBoxList1.SelectedValue.ToString();
    Label1.Text = manufSelect;
    
}

for basic understand you will get here Detail & Example
------------------------------------
http://www.w3schools.com/aspnet/control_checkboxlist.asp
DL M replied to msakt on 27-Jun-12 02:39 AM
code sample show here
-----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CheckBoxList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string msg = "You have selected the following countries:<br />";
if (ckeckboxlist1.Items[0].Selected)
{
msg = msg + ckeckboxlist1.Items[0].Text + "<br />";
}
if (ckeckboxlist1.Items[1].Selected)
{
msg = msg + ckeckboxlist1.Items[1].Text + "<br />";
}
if (ckeckboxlist1.Items[2].Selected)
{
msg = msg + ckeckboxlist1.Items[2].Text + "<br />";
}
if (ckeckboxlist1.Items[3].Selected)
{
msg = msg + ckeckboxlist1.Items[3].Text + "<br />";
}
Message.Text = msg;
}
protected void ckeckboxlist1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}