Itterate through a DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I have a datagrid in which I have placed a "Check box" in one of the
columns and then I have a button (outside of the grid) when the user presses,
I want to do something with each line in the grid in which the user has
clicked the check box. How do I iterate through the datagrid and find my
check box control so that I can test the values to see if it has been checked?

Thanks in advance for your assistnance.
 
Jim Heavey said:
If I have a datagrid in which I have placed a "Check box" in one of the
columns and then I have a button (outside of the grid) when the user
presses,
I want to do something with each line in the grid in which the user has
clicked the check box. How do I iterate through the datagrid and find my
check box control so that I can test the values to see if it has been
checked?

To find a value in a DataGrid (or datalist), you just need to do the
following:

Dim oAnswer as CheckBox

Dim oPositionID as Label



for each oGridItem as DataGridItem in DataGrid1.Items

oAnswer = CType(oGridItem.FindControl("lblAnswer"),CheckBox)

oPositionID = CType(oGridItem.FindControl("lblPositionID"),Label)

next



This will take you through the control chain for each DataGridItem and then
you use FindControl to find the control you are looking for by ID.



In my example, I am looking for a CheckBox and a Label on each DataGridItem.



Tom
 

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

Back
Top