Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to get value of selected dynamic dropdownlist in vb.net?

    Hello there,

    Currently I am working with the project which needs dynamically generated DROPDOWNLIST and i have generated dynamic DROPDOWNLIST but i am facing problem with getting the value of selected dropdownlist.

    Problem is described below to understand easily, so please let me know if you come to know the

    soln...

    Desciption:
    The system generated at least 30 dynamic dropdownlist, when this display the users can edit the information and Click the Update Button to update the dynamic dropdownlist information.

    The problems i facing is how i get the results of dynamic dropdownlist after users edit and save into database?

    Thanks,
    Tracy

  • #2
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Are you asigning ID values to your dynamically generated dropdownlists? If not what you can do I guess is use a random generator that will give you a unique value for each of your dropdownlist ID. You can then save these unique values to sessions or something. This way when someone clicks one of the values in a dropdownlist you will have something to compare inorder to find which dropdownlist they clicked.

    30 of them? Looks like you have your work cutout for yourself. I have never done dynamically generated dropdownlist so can tell you for sure how to fix your problem.

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually i need to do something like calendar, when the user choose year and month, it will come out the informantion in the format something like calendar, thats y i need to generate around 30 dropdownlist. By time i generate the dropdownlist i using the for loop method to call the infor from database n given the ID. but after call out the infor, the system allow user to update the infor, but how can i call back the dynamic dropdownlist ID? this is how the method i genarate the dynamic dropdownlist and came out the infor. but i facing a problem how to update the dropdownlist to correct database?


    Dim strWrkID As String
    Dim strYear As String
    Dim strMon As String
    Dim strDay As String
    Dim DD As String
    Dim DD2 As String

    strWrkID = ddlWrkID.SelectedItem.Text
    strYear = ddlYear.SelectedItem.Text

    If ddlMonth.SelectedItem.Text = "January" Then
    strMon = "1"
    strDay = "31"
    End If

    If ddlMonth.SelectedItem.Text = "February" Then
    strMon = "2"
    If strYear Mod 4 = 0 Then
    strDay = "29"
    Else
    strDay = "28"
    End If
    End If

    If ddlMonth.SelectedItem.Text = "March" Then
    strMon = "3"
    strDay = "31"
    End If
    If ddlMonth.SelectedItem.Text = "April" Then
    strMon = "4"
    strDay = "30"
    End If

    If ddlMonth.SelectedItem.Text = "May" Then
    strMon = "5"
    strDay = "31"
    End If

    If ddlMonth.SelectedItem.Text = "June" Then
    strMon = "6"
    strDay = "30"
    End If
    If ddlMonth.SelectedItem.Text = "July" Then
    strMon = "7"
    strDay = "31"
    End If
    If ddlMonth.SelectedItem.Text = "August" Then
    strMon = "8"
    strDay = "31"
    End If
    If ddlMonth.SelectedItem.Text = "September" Then
    strMon = "9"
    strDay = "30"
    End If
    If ddlMonth.SelectedItem.Text = "October" Then
    strMon = "10"
    strDay = "31"
    End If

    If ddlMonth.SelectedItem.Text = "November" Then
    strMon = "11"
    strDay = "30"
    End If

    If ddlMonth.SelectedItem.Text = "December" Then
    strMon = "12"
    strDay = "31"
    End If


    Dim count As Integer
    Dim j As Integer


    For count = 1 To strDay

    Dim DDT1 As DateTime = New DateTime(strYear, strMon, count)
    DD = DDT1.ToString("yyyy-MM-dd")

    Dim conn As Odbc.OdbcConnection
    Dim comm As Odbc.OdbcCommand
    Dim objDT01 As Odbc.OdbcDataReader
    Dim strDT01 As String

    conn = New Odbc.OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=dw;USER=birdbird;PASSWORD=123456;")

    strDT01 = "Select * From dw_tms_grpschd_dtl where GROUP_ID=? and YEAR=? and DT = '" & DD & "' "
    comm = New Odbc.OdbcCommand(strDT01, conn)
    comm.Parameters.Add("@GROUP_ID", strWrkID)
    comm.Parameters.Add("@YEAR", strYear)

    conn.Open()
    objDT01 = comm.ExecuteReader()


    While (objDT01.Read())
    DT01 = Convert.ToString(objDT01("DAYSCHD_ID"))
    End While


    objDT01.Close()

    Dim commDaySchd As Odbc.OdbcCommand
    Dim objDaySchd As Odbc.OdbcDataReader

    Dim strDaySchd As String
    strDaySchd = "Select * From dw_dayschd"
    commDaySchd = New Odbc.OdbcCommand(strDaySchd, conn)
    objDaySchd = commDaySchd.ExecuteReader()


    Dim lblDate As New Label
    lblDate.Visible = True
    lblDate.ID = count
    lblDate.Text = "" & count

    Dim ddlDynamic As New DropDownList
    ddlDynamic.Visible = True
    ddlDynamic.ID = count

    ddlDynamic.DataSource = objDaySchd
    ddlDynamic.DataTextField = ("DAYSCHD_ID")
    ddlDynamic.DataBind()

    Panel1.Controls.Add(New LiteralControl("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"))

    Panel1.Controls.Add(lblDate)
    lblDate.Style("width") = "20"
    Panel1.Controls.Add(ddlDynamic)


    If count Mod 7 = 0 Then
    Panel1.Controls.Add(New LiteralControl("<br>"))
    Panel1.Controls.Add(New LiteralControl("<hr>"))
    End If


    For i As Integer = 0 To ddlDynamic.Items.Count - 1

    If (ddlDynamic.Items(i).Text = Convert.ToString(DT01)) Then
    ddlDynamic.Items(i).Selected = True
    End If
    Next
    ' Panel1.Controls.Add(New LiteralControl("&nbsp"))
    ' Panel1.Controls.Add(New LiteralControl("&nbsp"))

    objDaySchd.Close()
    conn.Close()

    Next

  • #4
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    So Tracy1723 did you find out how to get the values from the dynamic created dropdown list? The reason I am asking is I was just working on how to get the values from dynamic created textbox's. It took me awhile but I worked it out, and it works good.

    I think you could use the same method to get the selected values from your dropdownlist. Let me know.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •