ToBe

ToBe

  • NA
  • 164
  • 94.7k

listitem not showing all values

May 2 2013 8:00 AM
Hi 


I have and Edit form contain a checkboxlist and when I'm trying to check the selected values from my databse it goes will in the loop but it will always show the first item in the Checkboxlist even if the saved values is morethan that .

this is my code :

 string sqlstr4 = "SELECT REG.ID, CETYPE.Type FROM  tblReges INNER JOIN tblGE ON tblReges.ID = CETYPE.ID where ID = tblReges.ID";
                SqlCommand cmd4 = new SqlCommand(sqlstr4, con);
                cmd4.CommandType = CommandType.Text;
                cmd4.CommandTimeout = 15;

                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet DS = new System.Data.DataSet(cmd.CommandText);
                ad.Fill(DS);

                if (DS.Tables[0].Rows.Count > 0)
                {
                    foreach (ListItem litem in CheckBoxList.Items)
                    {
                        if (litem.Text == DS.Tables[0].Rows[0].ItemArray[1].ToString())
                        {
                            litem.Selected = true;
                        }

                    }

                }

Answers (4)