Results 1 to 5 of 5

Thread: [02/03] change value of controls

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    [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.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    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

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    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.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width