iterate thru controls on page

  • Thread starter Thread starter Tina
  • Start date Start date
T

Tina

I need to find all of the datagrids on a page. How can I iterate through
all of the controls on a page to get their name and grab them as an object?
thanks,
T
 
no need to check for the id, you can directly check if the control is a
datagrid:

for each control as Control in Page.Controls
if control is DataGrid then
dim grid as DataGrid = ctype(control, DataGrid)
'can use the grid and get hte id via grid.Id
end if
next


Controls are embedded however, so you need to recursively loop:

sub LookForGrid(Control Parent)
for each control as Control in Parent
if control is DataGrid then
dim grid as DataGrid = ctype(control, DataGrid)
'can use the grid and get hte id via grid.Id
end if
if control.HasControls then
LookForGrid(control)
end if
next
end sub

Karl
 
Back
Top