Connecting Tech Pros Worldwide Forums | Help | Site Map

Maybe simple, but..

Newbie
 
Join Date: Oct 2008
Posts: 8
#1: Oct 27 '08
Please, can anyone tell me, why this does not work:
(I am a beginner)

Expand|Select|Wrap|Line Numbers
  1. Imports system.web.ui.Webcontrols
  2.  
  3. Dim ctrl As webcontrol
  4. Dim str as string
  5.  
  6. For Each ctrl In me.Controls
  7.  
  8. If ctrl.Controls.Count > 0 Then
  9.                 str= str & "Jel"
  10.             Else
  11.                 str = "nothing found"
  12.             End If
  13.         Next

kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Oct 27 '08

re: Maybe simple, but..


Quote:

Originally Posted by Jelle

Please, can anyone tell me, why this does not work:
(I am a beginner)

Expand|Select|Wrap|Line Numbers
  1. Imports system.web.ui.Webcontrols
  2.  
  3. Dim ctrl As webcontrol
  4. Dim str as string
  5.  
  6. For Each ctrl In me.Controls
  7.  
  8. If ctrl.Controls.Count > 0 Then
  9.                 str= str & "Jel"
  10.             Else
  11.                 str = "nothing found"
  12.             End If
  13.         Next

What makes you suspect that it is not working? What are you hoping that it will do?
OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 361
#3: Oct 27 '08

re: Maybe simple, but..


txtAnswer.text = str

You will get an answer then.
Newbie
 
Join Date: Oct 2008
Posts: 8
#4: Oct 27 '08

re: Maybe simple, but..


Excuse me, I wasn't complete in my question.
I want to make a SQL-string of the names and the values of all the control.id's and the control.text's like this.

Expand|Select|Wrap|Line Numbers
  1. For each ctrl in Me.Controls
  2.    strId = strId & ctrl.id & ", "
  3.    strValue = strValue & ctrl.text & ", "
  4. Next
  5.  
  6. strSQL = "INSERT INTO " & strId " VALUES " & strValue & ";"
Then I get the error:
Quote:
"Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.WebControl'."
Jelle
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#5: Oct 27 '08

re: Maybe simple, but..


Try adding this line above your loop:
Expand|Select|Wrap|Line Numbers
  1. Dim ctrl as WebControl
  2.  
Also, please use [CODE] [/CODE] tags when you are posting code.
Newbie
 
Join Date: Oct 2008
Posts: 8
#6: Oct 27 '08

re: Maybe simple, but..


Thanks, but I did so. See my first mail.
Jelle
Reply