comparing datatypes
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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.

Reply to this message...
 
    
Shiva
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

"rufus" <Click here to reveal e-mail address> wrote in message news:chrska$u13$Click here to reveal e-mail address...
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.

Reply to this message...
 
    
Cor Ligthert
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" <

Reply to this message...
 
    
One Handed Man \( OHM - Terry Burns \)
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

"rufus" <Click here to reveal e-mail address> wrote in message news:chrska$u13$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
rufus
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:u6Pp$Click here to reveal e-mail address...
[Original message clipped]

Thanks!

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "rufus" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

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

- or -

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
 
System.Diagnostics.Debug
System.EventArgs
System.Object
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.CheckBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.CheckBox
System.Windows.Forms.TextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com