|
-
May 31st, 2007, 10:46 AM
#1
Thread Starter
Hyperactive Member
eval a string into an object
say I have a textbox with attribute id="test_1"
How could I reference this id if I am in a loop
ex.
Code:
for i as Integer = 0 to 5
' I would like to give this textbox a value, I thought I could do something like
Eval("test_" & i).Value = "someValue"
' but that did not work, I also tried to do
dim tmpTB as Textbox = Ctype("test_" & i, TextBox)
Next
Is there a way to do this?
bsw
-
May 31st, 2007, 11:09 AM
#2
Re: eval a string into an object
If the text box is just on the page, it's just like normal application development: test_1.Text="....."
If it's within another object, such as a GridView, you need to do a FindControl for it:
Dim myTxt as TextBox = GridView1.FindControl("test1")
myTxt.Text="......"
-
May 31st, 2007, 12:02 PM
#3
Re: eval a string into an object
 Originally Posted by bsw2112
say I have a textbox with attribute id="test_1"
How could I reference this id if I am in a loop
ex.
Code:
for i as Integer = 0 to 5
' I would like to give this textbox a value, I thought I could do something like
Eval("test_" & i).Value = "someValue"
' but that did not work, I also tried to do
dim tmpTB as Textbox = Ctype("test_" & i, TextBox)
Next
Is there a way to do this?
bsw
In order to do this, you have to put the textboxes into a collection (array, list, arraylist...) then looping thru the collection.
-
May 31st, 2007, 03:49 PM
#4
Thread Starter
Hyperactive Member
Re: eval a string into an object
Thanks timeshifter and stanav
timeshifter, I went with your approach which resulted in this code
Code:
If PlanData.Rows.Count > 0 Then
For i As Integer = 0 To PlanData.Rows.Count - 1
Dim tmpDTB As New DoubleTextBox
tmpDTB = form1.FindControl("milestone2008_" & i + 1)
tmpDTB.Value1 = PlanData.Rows(i).Item(0)
tmpDTB.Value2 = GeneralUtilites.ConvertDate(PlanData.Rows(i).Item(1), "CAN")
Next
End If
instead of this code which was crazy. form1.FindControl is a blessing
Code:
If PlanData.Rows.Count > 0 Then
Select Case (PlanData.Rows.Count)
Case 1
milestone2008_1.Value1 = PlanData.Rows(0).Item(0)
milestone2008_1.Value2 = GeneralUtilites.ConvertDate(PlanData.Rows(0).Item(1), "CAN")
Case 2
milestone2008_1.Value1 = PlanData.Rows(0).Item(0)
milestone2008_1.Value2 = GeneralUtilites.ConvertDate(PlanData.Rows(0).Item(1), "CAN")
milestone2008_2.Value1 = PlanData.Rows(1).Item(0)
milestone2008_2.Value2 = GeneralUtilites.ConvertDate(PlanData.Rows(1).Item(1), "CAN")
Case X
etc....
End Select
End If
stanav
In order to do this, you have to put the textboxes into a collection (array, list, arraylist...) then looping thru the collection.
how do I go about putting controls from my page to a collection that I can then manipulate which would alter the value of the actual control on the page.
In other words say I have the 3 textboxes bellow.
Code:
<input name="foo1" id="foo1" /><br />
<input name="foo2" id="foo2" /><br />
<input name="foo3" id="foo3" /><br />
How would I add these three boxes to a collection and then use something like collection.value to make the three like so
<input name="foo1" id="foo1" value="foo1value" /><br />
<input name="foo2" id="foo2" value="foo2value" /><br />
<input name="foo3" id="foo3" value="foo3value" /><br />
bsw
Last edited by bsw2112; May 31st, 2007 at 03:59 PM.
-
Jun 4th, 2007, 03:04 PM
#5
Re: eval a string into an object
You don't need to. You can loop through the collection. If it's sitting in a table, div or simply the page, you can iterate through the .Controls collection of the object and test its type.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|