|
-
Jan 23rd, 2008, 09:25 AM
#1
Thread Starter
Fanatic Member
[02/03] change value of controls
I am wondering if you can work with controls dynamically but are not created dynamically.
Example:
I have three textbox controls: txtItem1.Text, txtItem2.Text, txtItem3.Text
Could I write a function that passes in the number and value and then I can set these through a function?
Would be something like so:
Code:
Public Sub sbChangeValue(ByVal iItemNum As Integer, ByVal sValue As String)
Eval(txtItem[iItemNum].Text) = sValue
End Sub
Thanks for your help in advance.
-
Jan 23rd, 2008, 10:36 AM
#2
Thread Starter
Fanatic Member
Re: [02/03] change value of controls
I think I figured out a way to do this.
Code:
Public Sub sbSetLoadControls(ByVal bTrueFalse As Boolean, ByVal iControlID As Integer)
Dim txtT As TextBox
Dim chkT As CheckBox
Dim ddlT As DropDownList
Dim alControls As ArrayList
Dim sControl As String
Dim sType As String
alControls = New ArrayList()
alControls.Add("txtItem")
alControls.Add("txtHeightL")
alControls.Add("txtWeightL")
alControls.Add("chkCars")
alControls.Add("ddlTrucks")
alControls.Add("txtMiles")
alControls.Add("txtNotes")
alControls.Add("txtTotal")
For Each sControl In alControls
sType = sControl.Substring(0, 3)
Select Case sType
Case "txt"
txtT = FindControl(sControl & iControlID.ToString)
txtT.Enabled = bTrueFalse
Case "chk"
chkT = FindControl(sControl & iControlID.ToString)
chkT.Enabled = bTrueFalse
Case "ddl"
ddlT = FindControl(sControl & iControlID.ToString)
ddlT.Enabled = bTrueFalse
End Select
Next
End Sub
-
Jan 23rd, 2008, 01:43 PM
#3
Re: [02/03] change value of controls
Yes, that sounds about right. You use FindControl to find a control by its ID, string, which means you can concatenate values.
I have a feeling, though, that what you're attempting to do can be done using some of ASP.NET's other controls. What are you doing on this page that involves dynamically accessing controls?
-
Jan 23rd, 2008, 02:04 PM
#4
Thread Starter
Fanatic Member
Re: [02/03] change value of controls
Basically I have a form that someone fills out and one dropdownbox is 1-9 and based on that response they have to fill out the same information that many times. Each one of these section has a bunch of textbox, checkbox, and radiobuttonlists that are stored in the database.
Yeah, it would be nice if I could make the whole thing once and call that (up to) 9 times. Not sure how that would be done, plus retrieving the info as well.
That is kind of why I went with making the last part 'L1' or 'L2' for the second so I can create a function to grab the info.
-
Jan 23rd, 2008, 04:31 PM
#5
Re: [02/03] change value of controls
You can use a repeater with defined controls in its ItemTemplate that repeats itself for each row you bind it to, or a gridview control or a formview control. This way you don't have to worry about what the ID of a control is, just with dealing with it one row at a time.
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
|