Skip to content

Return checkboxlist

Maneesh A N

Asked Oct 5, 2014, 8:18 PM EDT1 answer
Share
LinkedInX
HI

   I am facing problem in finding the checked items in checkbox list. Actually the list items for the    checkbox list are loaded from database. But by using the code below i am not able to find the         checked item in the list and the items are always returning false. Below is my code Can someone please help me with this?
   Please be correct.i need to get return items which is checked in check box list from in c#

Class1.connect();
SqlDataAdapter sda4 = new SqlDataAdapter("prcchklisttestupdate", Class1.con);
sda4.SelectCommand.CommandType = CommandType.StoredProcedure;
sda4.SelectCommand.Parameters.AddWithValue("@ibookingid", SqlDbType.Int).Value = label6.Text;
DataTable dt4 = new DataTable();
sda4.Fill(dt4);

for (int i2 = 0; i2 < dt4.Rows.Count; i2++)
{
foreach (string item in chkList1.Items)
{
if (item == dt4.Rows[i2][0].ToString())
{
chkList1.SelectedValue = true;
}
}

}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    i think problem with this loop
    make it as below and try.
    for (int i2 = 0; i2 < dt4.Rows.Count; i2++)
    {
    foreach (ListItem item in chkList1.Items)
    {
    if (item.Text == dt4.Rows[i2][0].ToString())
    {
    item.Checked= true;
    }
    }

    }

    u will get the item list using checkbox items as follow
    list<string> checkedList=chkList1.Items.where(d=>d.Checked==true).select(r=>r.Text).Tolist();
    0