ASP:DropDownList Question

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
 
A

AW

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top