ASP:DropDownList Question

Discussion in 'ASP .Net' started by Guest, Oct 29, 2003.

  1. Guest

    Guest Guest

    Hi All

    I have a form in which i build a table for a series of twenty questions,
    like a survey questionaire.

    I use the following function in a user control to create the DropdownList
    from the DB and in the loop that builds the table cells i call the function
    each time:

    Public Function Get_MultiDDL() As DropDownList

    Dim drDDLValues As SqlHelper
    Dim drDDLValuesList As SqlDataReader
    Dim i As Integer = 0
    ddlListBoxMulti = New DropDownList

    i = 0
    drDDLValuesList =
    drDDLValues.ExecuteReader(ConfigurationSettings.AppSettings("SQLServer"),
    CommandType.StoredProcedure, "csp_SELECT_Answer_Multi")
    ddlListBoxMulti.Items.Add(" ")
    ddlListBoxMulti.Items(i).Value() = 0
    i += 1

    Do While drDDLValuesList.Read()

    ddlListBoxMulti.Items.Add(drDDLValuesList.GetString(1))
    ddlListBoxMulti.Items(i).Value() = drDDLValuesList.GetInt32(0)
    i += 1
    Loop
    i = 0

    drDDLValuesList.Close()
    drDDLValuesList = Nothing
    drDDLValues = Nothing
    Return ddlListBoxMulti

    End Function


    Is there a better way to make one call and have the Dropdownlist available
    thruout the function that builds the table?
    What i am doing now is, as the loop executes, the function is called and it
    returns a dropdownlist. I would think i would be able to make one call to
    the DB, and have the DropDownlist available, instead of calling the function
    20 times as the table cells are built.

    thanks in advance





    --
    The Mighty Thor Lives
    http://www.themightythor.com
    Guest, Oct 29, 2003
    #1
    1. Advertising

  2. Guest

    AW Guest

    > I have a form in which i build a table for a series of twenty questions,
    > like a survey questionaire.
    >
    > ...
    > Dim drDDLValues As SqlHelper
    > Dim drDDLValuesList As SqlDataReader
    > ...
    > Do While drDDLValuesList.Read()
    >
    > ddlListBoxMulti.Items.Add(drDDLValuesList.GetString(1))
    > ...
    >
    > Is there a better way to make one call and have the Dropdownlist available
    > thruout the function that builds the table?


    How about binding the drDDLValuesList DataReader to the DropDownList? You
    set the DataSource to drDDLValuesList, set the DataTextField to the column
    name of the second column, and you're done. Don't forget to call DataBind()
    on the control.
    ---
    To reply, remove a "l" before the @ sign.
    AW, Oct 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,582
    mr2_93
    Oct 2, 2005
  2. tshad
    Replies:
    8
    Views:
    2,206
    tshad
    Oct 19, 2005
  3. =?Utf-8?B?SnVhbmpv?=

    GridView: Filtr DropDownList from another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,848
    =?Utf-8?B?SnVhbmpv?=
    Dec 23, 2005
  4. =?Utf-8?B?SnVhbmpv?=

    GridView: Filter DropDownList for another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,285
    =?Utf-8?B?SnVhbmpv?=
    Dec 29, 2005
  5. keithb
    Replies:
    1
    Views:
    11,916
    shauns1
    Nov 1, 2006
Loading...

Share This Page