.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification