PDA

View Full Version : looping through controls asp.net


allida77
06-04-2003, 02:43 PM
I have some checkboxes that are output server side. In asp.net how can I loop through the controls on page to get all checkboxes that are checked?

ReyN
06-06-2003, 04:15 PM
not sure if this is what you meant, but there is a working example on this page (http://aspalliance.com/aspxtreme/webforms/controls/allowinguserstodeleteitemsindatalist.aspx) that may be of help.

allida77
06-06-2003, 04:55 PM
I actually got it. I wasnt very specific in my post.


For Each ctl In pnlSurveys.Controls
Select Case ctl.GetType.FullName
Case "System.Web.UI.WebControls.CheckBox"
...........................
End Select
Next


I didnt realize you could loop through a panel like that.

ReyN
06-07-2003, 01:02 AM
you can loop thru any Controls collection, whether it's the parent page's, or any of its child controls', such as a Panel.

in fact, you can use for each (http://aspalliance.com/aspxtreme/aspnet/language/aspnetlanguages.aspx?pageno=12) to enumerate thru ANY collection in ASP.NET.

angiras
06-07-2003, 04:59 PM
you can be more specific if you don't want all the textBoxes for exemple

dim type as string = "System.Web.UI.WebControls.CheckBox"
Dim ctrl As Control
dim textId as string = "prefix_"

For Each ctrl In yourContainer.Controls

If ctrl.GetType().ToString() = type Then

If ctrl.ID.StartsWith(textId) Then
... ;-))
End If

End If

next