Help with Gridview Foreach and Row Cells

0 views
Skip to first unread message

mfawn

unread,
Nov 5, 2009, 8:04:48 PM11/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I have a gridview that I have added some checkboxes too. I have a
foreach loop that is returning if a checkbox has been clicked but I
also need to pull back one of the colums in that row so I know what
category is clicked.

EG:

Row 1 has a category id of 3 and checkbox is unchecked.
Row 2 has a category id of 12 and checkbox is unchecked.
Row 3 has a category id of 23 and checkbox is checked.
Row 4 has a category id of 54 and checkbox is unchecked.

I can get that the row 3 is checked but I can't get back the category
id to add it to the database.

I'm trying something like this:

foreach (GridViewRow di in GridView1.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("ShowAddress");
if (chkBx != null && chkBx.Checked)
// add DB code here
}
Reply all
Reply to author
Forward
0 new messages