Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
clsbo objbo = new clsbo();
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected)
{
objbo.Hobbies = CheckBoxList1.SelectedValue.ToString();
}

}

}

here i am only getting the first selected value from the checkboxcontrol but i just want
to get all the values from the checkboxlistcontrol.
Posted
Updated 9-Dec-14 2:24am
v2

string result="";

foreach(ListItem li in this.Checckboxlist1.Items)
{
if (li.selected==True)
{
string tu=li.value;
result=tu+","+result;
}
}
 
Share this answer
 
v2
Comments
raxhemanth 9-Dec-14 8:35am    
string result="";

foreach(ListItem li in this.Checckboxlist1.Items)
{
if (li.selected==True)
{
string tu=item.value;
result=tu+","+result;
}
}\
Here string tu = Item.value;// not available
string tu = Items.Values is available but getting error that is cannot implicitly convert collections system.collections to string. error how to solve this?
Tushar sangani 9-Dec-14 22:50pm    
Sorry for typing mistake
use
string tu =li.value;
Try..

C#
class clsbo
{
    public List<string> hobbies{ get; set; }
}


C#
clsbo objbo= new clsbo();
objbo.hobbies = new List<string>();
foreach (ListItem li in CheckBoxList1.Items)
{
  if(li.Selected)
  {
    if (li.Value != null && li.Value != "")
    {
        objbo.hobbies.Add(li.Value);
    }
   }
}
 
Share this answer
 
v4
Comments
raxhemanth 9-Dec-14 9:08am    
Line 32: if (Li.Selected)
Line 33: {
Line 34: objbo.Hobbies.Add(CheckBoxList1.SelectedValue.ToString());-------
Line 35: }
Line 36: }


Object reference not set to an instacne of an object
/\jmot 9-Dec-14 9:57am    
okk..got it..
if (li.Selected)
{
objbo.Hobbies.Add(li.Value.ToString());
}
raxhemanth 9-Dec-14 10:18am    
still getting the same jmot any way thankyou somuch for your help.
/\jmot 9-Dec-14 10:30am    
i just updated my answer, check now.
/\jmot 9-Dec-14 10:19am    
wait..let me see..

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