Adding dynamic controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fish

    #1

    Adding dynamic controls

    I am new to .NET and am looking for a way to create a dynamic list of
    textboxes. Basically, the form begins with a row of three textboxes and
    the user can add another row (as many as they choose) by clicking on a
    link ("add another row"). Here is a sub that I have that fires when the
    page loads and also when the user clicks the link.

    The form will display the additional rows when the user clicks the
    link, but, unfortunately, every time the user does click to add another
    row, I lose the post data. Is there a way around this or a better way
    to accomplish this?


    Private Sub generatePlaceho lders()
    Dim n As Int32 = rowNum.Value
    Dim i As Int32

    For i = 0 To n

    Dim TextBox = New TextBox
    TextBox.ID = "txtOne" + i.ToString
    TextBox.EnableV iewState = True
    plcMedicine.Con trols.Add(New TextBox)
    plcMedicine.Con trols.Add(New LiteralControl( "<br>"))

    Dim TextBox1 = New TextBox
    TextBox1.ID = "txtTwo" + i.ToString
    TextBox1.Enable ViewState = True
    plcDose.Control s.Add(New TextBox)
    plcDose.Control s.Add(New LiteralControl( "<br>"))

    Dim TextBox2 = New TextBox
    TextBox2.ID = "txtThree" + i.ToString
    TextBox2.Enable ViewState = True
    plcQuantity.Con trols.Add(New TextBox)
    plcQuantity.Con trols.Add(New LiteralControl( "<br>"))

    Next
    End Sub

Working...