ASP:DropDownList Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

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
 
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.
 
Back
Top