By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

Maybe simple, but..

P: 8
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
Oct 27 '08 #1
Share this Question
Share on Google+
5 Replies


kenobewan
Expert 2.5K+
P: 4,871
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?
Oct 27 '08 #2

OuTCasT
100+
P: 374
txtAnswer.text = str

You will get an answer then.
Oct 27 '08 #3

P: 8
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:
"Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.WebControl'."
Jelle
Oct 27 '08 #4

Curtis Rutland
Expert 2.5K+
P: 3,256
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.
Oct 27 '08 #5

P: 8
Thanks, but I did so. See my first mail.
Jelle
Oct 27 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.