locked
How to assign a DropDownList a value from Request.QueryString RRS feed

  • Question

  • Hi All,

    I am having an issue with filling in a dropdownlist i have on my page with data called from stored procedure. I am trying to create a DDL server side as this is the easiest way for me to do it but so far i am getting confused on how to go about it the right way as nothing seems to work.

    So far i have tried the following but i think i am missing some steps and i have no idea what they are..

     If Request.QueryString("userid") <> "" Then

                Dim ddl As DropDownList
                Dim ddlResult As New DataSet
                ddlResult = GetUserName.ddlData(Request.QueryString("userid").ToString)

                Dim dr As DataRow = ddlResult.Tables(0).NewRow
                dr("description") = String.Empty
                ddlResult.Tables(0).Rows.InsertAt(dr, 0)
                ddlResult.AcceptChanges()

                ddl.DataValueField = "description"
                ddl.DataTextField = "description"
                ddl.DataSource = ddlResult.Tables(0)
                ddl.DataBind()
            End If

    This tells me the ddl is being used before it has been assigned a value which i'm not sure how to fix.

    I thought about ListItems but not sure how to implement them into the code for the ddlData function.

    I need the drop down list to hold the data pulled from the GetUserName.ddlData function but i cant seem to work this out.

    Any help would be appreciated thank you

    • Moved by Caillen Friday, January 23, 2015 9:00 AM
    Thursday, January 22, 2015 12:12 PM

Answers