0
string user = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["StatusConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string result = "SELECT [UserID],[Status] FROM [MSCAssignment].[dbo].[StatusButton] WHERE [Status]='1'";
con.Open();
SqlCommand showresult = new SqlCommand(result, con);
SqlDataReader rd = showresult.ExecuteReader();
//string dd = rd["UserID"].ToString();
CheckBoxList chkbx = (CheckBoxList)FindControl("UserID");
//ListItem currentCheckBox = chkbx.Items.FindByValue(rd["UserID"].ToString());
for (int i = 0; i < chkbx.Items.Count; i++)
{
    if (chkbx.Items[i].Selected)
    {
        user = chkbx.Items[i].Value = ";";
    }
}
John Wu
  • 50,556
  • 8
  • 44
  • 80

1 Answers1

0

This line would throw the error if the connection string was not found:

string constr = ConfigurationManager.ConnectionStrings["StatusConnectionString"].ConnectionString;

This will throw the error if the control doesnt' exist:

CheckBoxList chkbx = (CheckBoxList)FindControl("UserID");
John Wu
  • 50,556
  • 8
  • 44
  • 80