Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid with CheckBox - How to read checked rows

Reply
Thread Tools

DataGrid with CheckBox - How to read checked rows

 
 
Magnus
Guest
Posts: n/a
 
      05-18-2005
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
 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      05-18-2005
> 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
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
CheckBox Checked=false when checked in DataList yurps ASP .Net 1 02-29-2008 01:08 PM
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip mehul ASP .Net 0 05-03-2004 12:07 PM
Checkbox - database checkbox, if checked gives value of 1 .. how to sum ? randy Perl Misc 13 11-01-2003 05:39 AM
Unable to detect Checked property of Checkbox in Datagrid Jon ASP .Net Web Controls 5 09-18-2003 10:54 PM



Advertisments