Thursday, February 4, 2010

Iterating through controls in form + vb.net

Looop through the controls...

Private

SetTooltip(oControl, strToolTip)
FindToolTipControl(oControl.Controls, strToolTip)

Sub FindToolTipControl(ByVal oControlCollection As ControlCollection, ByVal strToolTip As String)For Each oControl AsControl In oControlCollectionNext

......................



Private Sub SetTooltip(ByVal oControl As Control, ByVal strToolTip As String)Select CaseoControl.GetType.ToStringCase "System.Web.UI.WebControls.TextBox"

Response.Write(

Dim otxt As TextBox = oControl.FindControl(oControl.ID)"
" & "TextBox:- " & otxt.Text.ToString())Case"System.Web.UI.WebControls.DropDownList"

Response.Write(

Dim oDdl As DropDownList = oControl.FindControl(oControl.ID)"
" & "DropDown :- " & oDdl.Text.ToString())Case"System.Web.UI.WebControls.RadioButton"

Response.Write(

Dim oRdbtn As RadioButton = oControl.FindControl(oControl.ID)"
" & "RadioButton:- " & oRdbtn.Text.ToString())Case "System.Web.UI.WebControls.CheckBox"


Dim oChkbx As CheckBoxList = oControl.FindControl(oControl.ID)'Response.Write("
" & "Ckeckboxloist" & oChkList.Items.Count.ToString())


Response.Write(

Dim MyItem As ListItemFor Each MyItem In oChkbx.Items"
" & "Ckeckbox:- " & MyItem.Text.ToString())Next

Case "System.Web.UI.WebControls.Label"

Response.Write(

Dim oLabel As Label = oControl.FindControl(oControl.ID)"
" & "Label:- " & oLabel.Text)Case"System.Web.UI.WebControls.CheckBoxList"


Dim oChkList As CheckBoxList = oControl.FindControl(oControl.ID)'Response.Write("
" & "Ckeckboxloist" & oChkList.Items.Count.ToString())


Response.Write(

Dim MyItem As ListItemFor Each MyItem In oChkList.Items"
" & "Ckeckboxlist:- " & MyItem.Text.ToString())Next

Case "System.Web.UI.HtmlControls.HtmlTableRow"


Dim oTbrw As HtmlTableRow = oControl.FindControl(oControl.ID)'Response.Write("
" & "Table row:- " & oTbrw.InnerText.ToString())

End Select

End Sub
End Sub

No comments:

Post a Comment