iterate thru controls on page

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
 
K

Karl Seguin

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
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top