DataGrid with CheckBox - How to read checked rows


M

Magnus

I have added a checkbox to a dataset that I bind to a datagrid:

DataColumn colBoolean = new DataColumn ("chkBox");
colBoolean.DataType = System.Type.GetType ("System.Boolean");
colBoolean.DefaultValue = true;
ds.Tables["etikett"].Columns.Add (colBoolean);

grd.DataSource = ds.Tables["etikett"].DefaultView;
grd.DataBind();

How do I read all the rows that have been checked? I want to create a
report (crystal) for only the checked rows.

Regards,
Magnus
 
Ad

Advertisements

B

Brock Allen

How do I read all the rows that have been checked? I want to create a
report (crystal) for only the checked rows.

You'll have to loop over the rows in the DataGrid and access the Cell that
contains the checkbox. Once you have the cell, use FindControl("YourCheckBoxID")
to get the CheckBox control then get its Checked property.

// pseudocode
foreach (DataGridRow row in grid.Rows)
{
Control c = row.Cells[TheIndexOfYourCheckBoxColumn].FindControl("YourCheckBoxID");
CheckBox cb = c as CheckBox;
if (cb != null && cb.Checked)
{
// this row has been selected
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top