Tech
Forums
Jobs
Books
Events
Live
Learn
More
Training
Interviews
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
6
Reply
Create checkboxes dynamically
Chriz L
Dec 12 2016 7:35 AM
286
Reply
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.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
6
)
Next Recommended Forum
data table to list
how to update db,when shutdown s\m without browser close app