Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dropdown List data binding

Reply
Thread Tools

Dropdown List data binding

 
 
Binod Nair
Guest
Posts: n/a
 
      01-16-2004
Hi All,

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

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

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


 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      01-16-2004
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

<aspropDownList 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi All,
>
> This is what I am trying to do.I have an aspx page with the the following
> code block.
>
> <aspropDownList id="DropDownList1" runat="server" DataSource="<%#
> GetUsers%>" DataTextField="user_email" DataValueField="user_id">
> </aspropDownList>
>
> 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
>
>



 
Reply With Quote
 
 
 
 
Binod Nair
Guest
Posts: n/a
 
      01-16-2004
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:%23%(E-Mail Removed)...
> 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
>
> <aspropDownList 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi All,
> >
> > This is what I am trying to do.I have an aspx page with the the

following
> > code block.
> >
> > <aspropDownList id="DropDownList1" runat="server" DataSource="<%#
> > GetUsers%>" DataTextField="user_email" DataValueField="user_id">
> > </aspropDownList>
> >
> > 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
> >
> >

>
>



 
Reply With Quote
 
Hermit Dave
Guest
Posts: n/a
 
      01-16-2004
do this
<aspropDownList 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi All,
>
> This is what I am trying to do.I have an aspx page with the the following
> code block.
>
> <aspropDownList id="DropDownList1" runat="server" DataSource="<%#
> GetUsers%>" DataTextField="user_email" DataValueField="user_id">
> </aspropDownList>
>
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot select two-way data binding property on a dropdown list con Mike Milian ASP .Net 0 04-14-2008 02:49 AM
Trouble binding a dropdown list in a detailsview. =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= ASP .Net 6 11-24-2007 05:39 AM
Help binding a DataTable to a DropDown List keithb ASP .Net 1 04-04-2006 08:04 AM
Data binding in TextBox after dropdown list indexchanged =?Utf-8?B?ZGF2aWQ=?= ASP .Net 5 04-04-2005 12:43 PM
Binding dataset to a Dropdown list Fraggle_Rock_1@yahoo.com ASP .Net 2 09-14-2004 11:36 AM



Advertisments