Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get selected checkbox item from check box List
Posted

C#
string strchecked="";
 for (int i = 0; i < chk1.Items.Count; i++)
                {
                    if (chk1.Items[i].Selected)
                    {                      
			if(strchecked.Trim()==string.empty())
			{
				strchecked=chk1.Items[i].Text;	
			}
			else
			{
				strchecked=strchecked+","+chk1.Items[i].Text;	
			}

                    }
                }
 
Share this answer
 
v2
Comments
soniya sangal 11-Oct-11 6:49am    
its not working
get error........
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The handle is invalid.)
Hi,

you can try this code.
C#
CheckBoxList1.SelectedItem


But checkboxlist is you can select multiple options in that case it returns only

lower item that means

top selected item in your selected items.

If you want to get all selected items then

C#
foreach (ListItem boxItem in CheckBoxList1.Items)
{
  

  if (boxItem.Selected == true)
  {
    categoryID.Add((string)boxItem.Value);
   
  }
}


All the Best
 
Share this answer
 
v2
try in this way

SQL
if (chkboxlist.Items[0].Selected == true)
{
//do something you want 
}
else if (chkboxlist.Items[1].Selected == true)
{
//do something you want 
}
else if (chkboxlist.Items[2].Selected == true)
{
//do something you want 
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900