convert string to object type

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

convert string to object type

 
0
  #1
Sep 18th, 2009
Hi

I have a procedure that performs checks on controls in my page against rules set in a SQL table. It all works fine except that when im casting the control e.g.
  1. CType(Me.Page.FindControl(control1), TextBox).Text

and its a dropdownlist it of course fails.

Im trying to create a variable that gets populated from the table with the correct control type and then use this in the cast. i.e replace textbvox with my variable that could say either 'textbox' or 'dropdownlist'

but if i just put the string value variable in it gives error 'Type 'ControlType' is not defined'.

I wonderd if anyonme had any ideas
Please mark this post as 'Solved' if it has helped and fixed your issue.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 21
Reputation: Datsun90 is an unknown quantity at this point 
Solved Threads: 0
Datsun90 Datsun90 is offline Offline
Newbie Poster

Re: convert string to object type

 
0
  #2
Sep 21st, 2009
Use a condition before casting the control like this:

  1. If TypeOf(Me.Page.FindControl(control1)) IS DropDownList Then
  2. CType(Me.Page.FindControl(control1), DropDownList).SelectedIndex = xyz
  3. End If

regards,
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC