Hello,
I want to create dynamically checkboxes based on sproc result (one checkbox for each row).Here's my code:
- public void selectChecks(Label appno, Label Cat)
- {
- SqlConnection connection = getConnection();
- try
- {
- connection.Open();
- SqlCommand command = new SqlCommand("ChecksSelect", connection);
- command.CommandType = CommandType.StoredProcedure;
-
- command.Parameters.Add("@Appno", SqlDbType.Int).Value = Convert.ToInt32(appno.Text);
- command.Parameters.Add("@Cat", SqlDbType.Int).Value = Convert.ToInt32(Cat.Text);
-
- SqlDataAdapter adapter = new SqlDataAdapter(command);
- DataSet ds = new DataSet();
- adapter.Fill(ds);
-
- foreach (DataTable table in ds.Tables)
- {
- foreach (DataRow dr in table.Rows)
- {
- CheckBox check = new CheckBox();
- check.Text = dr["CheckDescr"].ToString();
- if (dr["CheckResult"].ToString() == "1")
- check.Checked = true;
- else
- check.Checked = false;
- check.ID = dr["CheckCode"].ToString() + "Lbl";
- }
- }
- }
- catch (Exception ex)
- { myMessageBox(ex.Message); }
- }
How can I place them in my form's table?
Thank you in advance.