eval ?!?
-
Hello, Suppose I have 3 textboxes named: txtBox1, txtBox2 and txtBox3 Now for some reason I want to fill the boxes depending on their number: I mean something like this: txtBox(i).Text = "something" I know this is ridiculous but I hope you guys see what I mean. (something like the javascript eval function) Can I do something like that in VB-code?? Thanks for the comments respect 2B respected
-
Hello, Suppose I have 3 textboxes named: txtBox1, txtBox2 and txtBox3 Now for some reason I want to fill the boxes depending on their number: I mean something like this: txtBox(i).Text = "something" I know this is ridiculous but I hope you guys see what I mean. (something like the javascript eval function) Can I do something like that in VB-code?? Thanks for the comments respect 2B respected
Well, you can loop through the Controls collection of your page. Then check the type of the control (to see if it is indeed a textbox) and then get the id (which will be a string) and do your string manipulation on that. in code it would be something like:
For Each oControl As Control In Me.Controls If oControl.GetType().Name = "TextBox" Then If oControl.ID = "txtBox1" Then CType(oControl, TextBox).Text = "something" End If End If Next
This should give you an idea of how to do it. Gideon
-
Well, you can loop through the Controls collection of your page. Then check the type of the control (to see if it is indeed a textbox) and then get the id (which will be a string) and do your string manipulation on that. in code it would be something like:
For Each oControl As Control In Me.Controls If oControl.GetType().Name = "TextBox" Then If oControl.ID = "txtBox1" Then CType(oControl, TextBox).Text = "something" End If End If Next
This should give you an idea of how to do it. Gideon
-
Or you can use make a loop from 1 to x and then in the loop you place
ctype(me.FindControl("txtBox" & i),TextBox).Text = "something"