Checkbox in datagrid

T

Tommy

I have a datagrid with a checkbox in one col. It's bound to a row in my
table.

I need to allow my user to select multiple records then process each one
when they click a button.

How can i iterate through each row in my grid and check the checkbox's
checked property? I have my pk hidden in the grid so I can use it to pass to
my stored proc. I just can't seem to iterate through and check each control

Ultimately it would be nice to be able to get the datarow for each row that
is bound to the grid and check the fields but i'm sure that's a little much
to ask.

Thanks for any tips.

Tommy
 
P

Phillip Williams

Upon submit you can either
1) loop through the entire datagrid items collection:
foreach (DataGridItem item in dgAddresses)
{
switch (item.ItemType )
{
case ListItemType.Item:
//find the individual controls
break;
}
}

2) use the event handler of the checkbox as the entry point to process the
row that was selected as in this example:
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx

In both cases you can get the datarow that was selected from the datagrid
item (let's call it dgItem) by a formula such as:
DataRow dr = dt.Rows.Find(DataGrid1.DataKeys(dgItem.ItemIndex));
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top