473,388 Members | 1,385 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,388 software developers and data experts.

Dropdown List data binding

Hi All,

This is what I am trying to do.I have an aspx page with the the following
code block.

<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%#
GetUsers%>" DataTextField="user_email" DataValueField="user_id">
</asp:DropDownList>

GetUsers is defined in the .vb file

Public Function GetUsers() As DataSet

Dim ds As DataSet
ds =
SqlHelper.ExecuteDataset(ConfigurationSettings.App Settings("ConnectionString
"), CommandType.Text, "select user_id , user_email from users")
Return ds

End Function
I am kind of frustrated that I cannot make this thing work.What am I doing
wrong ?

--binod
Nov 18 '05 #1
3 2499
I never have liked binding data using <%# %>, because it sure looks old
asp'ey to me. So I'll tell you how I would do it. I've never seen that
SqlHelper object either, but I'll assume it is returning a valid dataset.

in your page_load, (or anywhere else really)
add this

DropDownList1.dataSource = GetUsers()
DropDownList1.DataTextField = "user_email"
DropDownList1.DataValueField = "user_id"
DropDownList1.DataBind()

then in your aspx file, where you want the DropDown you can just put

<asp:DropDownList id="DropDownList1" runat="server" />

where you want the dropdown.
and it should work.

Another thing too, depending on what you are doing, you may want to just use
a sqldatareader to populate this box, instead of passing around a dataset,
especially if you have no intention of ever editing the items in the box.

--Michael

"Binod Nair" <na*******@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi All,

This is what I am trying to do.I have an aspx page with the the following
code block.

<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%#
GetUsers%>" DataTextField="user_email" DataValueField="user_id">
</asp:DropDownList>

GetUsers is defined in the .vb file

Public Function GetUsers() As DataSet

Dim ds As DataSet
ds =
SqlHelper.ExecuteDataset(ConfigurationSettings.App Settings("ConnectionString "), CommandType.Text, "select user_id , user_email from users")
Return ds

End Function
I am kind of frustrated that I cannot make this thing work.What am I doing
wrong ?

--binod

Nov 18 '05 #2
I know its ASP style.But I am not sure why is this not working.
SQLHelper is the Microsoft Dataccess Class whcih does return a valid
Dataset.

The way u said , it works fine.I just want to make it work like this.Any
clues why is it not returning any data.
"Michael" <raterus@localhost> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
I never have liked binding data using <%# %>, because it sure looks old
asp'ey to me. So I'll tell you how I would do it. I've never seen that
SqlHelper object either, but I'll assume it is returning a valid dataset.

in your page_load, (or anywhere else really)
add this

DropDownList1.dataSource = GetUsers()
DropDownList1.DataTextField = "user_email"
DropDownList1.DataValueField = "user_id"
DropDownList1.DataBind()

then in your aspx file, where you want the DropDown you can just put

<asp:DropDownList id="DropDownList1" runat="server" />

where you want the dropdown.
and it should work.

Another thing too, depending on what you are doing, you may want to just use a sqldatareader to populate this box, instead of passing around a dataset,
especially if you have no intention of ever editing the items in the box.

--Michael

"Binod Nair" <na*******@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi All,

This is what I am trying to do.I have an aspx page with the the following code block.

<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%#
GetUsers%>" DataTextField="user_email" DataValueField="user_id">
</asp:DropDownList>

GetUsers is defined in the .vb file

Public Function GetUsers() As DataSet

Dim ds As DataSet
ds =

SqlHelper.ExecuteDataset(ConfigurationSettings.App Settings("ConnectionString
"), CommandType.Text, "select user_id , user_email from users")
Return ds

End Function
I am kind of frustrated that I cannot make this thing work.What am I doing wrong ?

--binod


Nov 18 '05 #3
do this
<asp:DropDownList id="DropDownList1" runat="server">

in your code behind file
if(!Page.IsPostBack)
{
DataSet myDS = GetUsers();
DropDownList1.DataSouce = myDS;
DropDownList1.DataTextField =
myDS.Tables[0].Columns["user_email"].toString();
DropDownList1.DataValueField =
myDS.Tables[0].Columns["user_id"].toString();
DropDownList1.DataBind();
}
this is c# code convert to equivalent VB code

--
Regards,

HD

Once a Geek.... Always a Geek
"Binod Nair" <na*******@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi All,

This is what I am trying to do.I have an aspx page with the the following
code block.

<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%#
GetUsers%>" DataTextField="user_email" DataValueField="user_id">
</asp:DropDownList>

GetUsers is defined in the .vb file

Public Function GetUsers() As DataSet

Dim ds As DataSet
ds =
SqlHelper.ExecuteDataset(ConfigurationSettings.App Settings("ConnectionString "), CommandType.Text, "select user_id , user_email from users")
Return ds

End Function
I am kind of frustrated that I cannot make this thing work.What am I doing
wrong ?

--binod

Nov 18 '05 #4

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

Similar topics

4
by: Brian Conway | last post by:
I need some help on binding a datareader to a dropdown box. I have included the code for the dropdown below. It builds with no errors, but returns no results. Any help would be appreciated. ...
0
by: Pietje puk | last post by:
Hello, Since im quite new to ASP.NET i wanted to ask you folks what the best way is to create a WebForm for modifying 1 field from a record. The manipulation of this field can be done by using...
4
by: Paul | last post by:
I have a dropdown list box and a button on a web form, the autopost back is false for the dropdown list box and button. When the button is pushed the selection in the dropdownlist box is lost,...
5
by: david | last post by:
I have a question in the following. Any one could give me a help? Thanks David The dataset is declared and created at Class level. My source code is here: Private Sub...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
1
by: kashifsulemani | last post by:
Combo Box DropDown Style. A combo box is bound to a data table field name. When combo box has simple / drop down style then bound is successful. Other hand if Combo box has drop down list...
8
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables...
2
by: pavanip | last post by:
Hi, I have a problem with binding data to dropdownlist from database in alphabetical order. My database contains some fields like All,Air,Airline,Books,Cars etc. There are 2 dropdown...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.