comparing datatypes

  • Thread starter Thread starter rufus
  • Start date Start date
R

rufus

Hi,

I want to loop through the web controls on a web form and depending on
whether it is a textbox, checkbox etc perform an action.

I first tried a case statement:

Dim Cols As String() = {"vorName", "nachName", "sacked", "employeeID"}

Dim I As Integer

For I = 0 To 1

Select case E.Item.FindControl("edit_" & Cols(I)).getType()

Case System.Web.UI.WebControls.TextBox

' perform action

I found out that case statements only support the basic datatypes. Does
anyone know of a good way to do this?

Thanks in advance.
 
For Each c As Control In Me.Controls

If TypeOf c Is TextBox Then

Debug.WriteLine(c.Name)

End If

Next


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Use the TypeOf keyword with the control instance name as in:

If TypeOf <ctl> Is CheckBox Then
' Action for checkbox
Else If TypeOf <ctl> Is TextBox Then
' Action for text box
End If

Hi,

I want to loop through the web controls on a web form and depending on
whether it is a textbox, checkbox etc perform an action.

I first tried a case statement:

Dim Cols As String() = {"vorName", "nachName", "sacked", "employeeID"}

Dim I As Integer

For I = 0 To 1

Select case E.Item.FindControl("edit_" & Cols(I)).getType()

Case System.Web.UI.WebControls.TextBox

' perform action

I found out that case statements only support the basic datatypes. Does
anyone know of a good way to do this?

Thanks in advance.
 
One Handed Man ( OHM - Terry Burns ) said:
For Each c As Control In Me.Controls

If TypeOf c Is TextBox Then

Debug.WriteLine(c.Name)

End If

Next

Thanks!
 
Rufus,

For a webform it is a little bit else than documented when the controls are
not on a panel.

\\\
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim frm As Control = Me.FindControl("Form1")
Dim ctl As Control
For Each ctl In frm.Controls
If TypeOf ctl Is TextBox Then
DirectCast(ctl, TextBox) = "" 'or whatever
End If
Next
///

I hope this helps

Cor
"rufus" <
 
* "rufus said:
I want to loop through the web controls on a web form and depending on
whether it is a textbox, checkbox etc perform an action.

I first tried a case statement:

Dim Cols As String() = {"vorName", "nachName", "sacked", "employeeID"}

Dim I As Integer

For I = 0 To 1

Select case E.Item.FindControl("edit_" & Cols(I)).getType()

Case System.Web.UI.WebControls.TextBox

' perform action

I found out that case statements only support the basic datatypes. Does
anyone know of a good way to do this?

\\\
If TypeOf ... Is TextBox Then
...
ElseIf...Then
...
....
End If
///

- or -

\\\
Select Case True
Case TypeOf ... Is TextBox
...
Case...
...
...
End Select
///
 

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