dynamic values for dynamic controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharathi228
    New Member
    • Jul 2008
    • 28

    dynamic values for dynamic controls

    my code for retrieving values from database


    Dim da As New SqlDataAdapter( "select parameter_name, parameter_units from sys_params", con)
    If con.State = ConnectionState .Closed Then
    con.Open()
    End If
    Dim ds As New DataSet
    Dim name, unit ,namunt As String
    da.Fill(ds, "sys_params ")
    For Each r In ds.Tables(0).Ro ws
    name = r.Item("paramet er_name")
    unit = r.Item("paramet er_units")
    namunt = name & "," & unit
    next



    code for dynamic labels and textboxes



    For i = 0 To inttxtcnt


    Dim newcontrol As New TextBox
    Dim NewLablecontrol As New Label
    'Assign the Location for Dynamic controls for Textbox and Labelcontrol
    newcontrol.Top = 20 * i
    NewLablecontrol .Top = 20 * i
    newcontrol.Left = 80
    'Assign the Text for Lable controls
    NewLablecontrol .Text = namunt
    Me.Controls.Add (NewLablecontro l)
    Me.Controls.Add (newcontrol)
    Next i


    two codes are working fine.

    but here my problem is a first retrieving value from database is assiging to first label
    second value to second label.
    and so on...........

    so may be i think it is possible through nested loops


    so anyone please help me with the code
  • bharathi228
    New Member
    • Jul 2008
    • 28

    #2
    Dynamic values for dynamic tables

    hi,

    iam doing a windows application.i have a requirement like to create labels and textboxes dynamically at runtime.
    and data is coming from database. based on the columns controls should be created and data is to be loaded in them.
    if the table is having 6 columns then 6 labels and textboxes should be created and corresponding data to be loaded.



    my code for retrieving values from database


    Dim da As New SqlDataAdapter( "select parameter_name, parameter_units from sys_params", con)
    If con.State = ConnectionState .Closed Then
    con.Open()
    End If
    Dim ds As New DataSet
    Dim name, unit ,namunt As String
    da.Fill(ds, "sys_params ")
    For Each r In ds.Tables(0).Ro ws
    name = r.Item("paramet er_name")
    unit = r.Item("paramet er_units")
    namunt = name & "," & unit
    next



    code for dynamic labels and textboxes



    For i = 0 To inttxtcnt


    Dim newcontrol As New TextBox
    Dim NewLablecontrol As New Label
    'Assign the Location for Dynamic controls for Textbox and Labelcontrol
    newcontrol.Top = 20 * i
    NewLablecontrol .Top = 20 * i
    newcontrol.Left = 80
    'Assign the Text for Lable controls
    NewLablecontrol .Text = namunt
    Me.Controls.Add (NewLablecontro l)
    Me.Controls.Add (newcontrol)
    Next i


    two codes are working fine.

    but here my problem is a first retrieving value from database is assiging to first label
    second value to second label.
    and so on...........

    so may be i think it is possible through nested loops


    so anyone please help me with the code

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Please do not double post. If you can't find your original thread, please click the My Subscriptions link at the top of the page. If you feel that your thread has been neglected, you can reply to it to bump it back to the top.

      Threads merged.

      MODERATOR

      Comment

      Working...