473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

ASP:DropDownList Question


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.Ap pSettings("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.GetStrin g(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
Nov 17 '05 #1
1 969
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.GetStrin g(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.
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ganesh Kolappan via .NET 247 | last post by:
Hi I am trying to populate a <asp:dropdownlist> in a XSLT file withdatasource pointing to a C# codebehind file method which returnsa dataview. I am using XSLT extension object. But I am...
1
by: Marius | last post by:
Hi all, I need an asp:dropdownlist on a webform that is databound to a dataset. This works fine and returns the data to populate my dropdownlist. In the DB I only have valid data, but I need a...
1
by: Harry | last post by:
Hi, Just seeing if anyone can help me with a problem I am having with drop down lists. - I have a asp:dropdownlist that gets its values from a database. - The user then selects a value then...
2
by: amessimon | last post by:
I need to display a drop down list which holds up to 250 listitems. I'd like to create this programmatically rather than have to hardcode it into the page. For example <asp:DropDownList...
1
by: Urmal Patel via .NET 247 | last post by:
I have problem with asp:Dropdownlist. I have a dropdownlist control in Page1.aspx and I want to assign value and Text to dropdown list form Page2.aspx from java script function. I am able to assign...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
1
by: Xuanly ly via .NET 247 | last post by:
asp:dropdownlist always display infront of everything and I can't make it display behind HELP HELP help!!!. <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1"...
2
by: HH | last post by:
Hi, I have a dropdown list that is datafilled via a SQL table. The text part is always unique. (A list of countries) Each country is assigned one of three numbers. (This being the 'value' of...
1
by: Miguel Dias Moura | last post by:
Hello, I have two questions concerning Asp:DropDownList 1. How to fill a DropDownList from runtime and set its default item? 2. How do use a DropDownList in each datagrid record? All...
2
by: John Smith | last post by:
I have this DataGrid: <asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateColumn HeaderText="SM"> <ItemTemplate> <asp:Label id="Label2" runat="server"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.