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

dropdownlist databind problems

Hi,

My function returns a datareader object containing only one column of
datatype money. In asp.net I want to bind this datareader to a dropdownlist.
Can anyone suggest me how to do this with some sample code if possible.

Thanks

Srinivas
Nov 18 '05 #1
3 1405
I found it best to load them in functions such as below.

public static void Loadlist(DropDownList thisDropDownList , SqlDataReader
dr)
{
thisDropDownList.Items.Clear();
ListItem li;
while(dr.Read())
{
li = new ListItem(dr[1].ToString().Trim(),dr[0].ToString().Trim());
thisDropDownList.Items.Add(li);
}
dr.Close();
}

"Srinivas" <an********@NO.JUNK.MAIL> wrote in message
news:e#**************@TK2MSFTNGP09.phx.gbl...
Hi,

My function returns a datareader object containing only one column of
datatype money. In asp.net I want to bind this datareader to a dropdownlist. Can anyone suggest me how to do this with some sample code if possible.

Thanks

Srinivas

Nov 18 '05 #2
You can assign your reader to the DropDownList control's "DataSource"
property and call the DataBind() method. You must also set the
DropDownList's "DataTextField" property to the column that you want to bind
to the control.
Here are some code pieces:

reader = command.ExecuteReader();
ddList.DataSource = reader;
ddList.DataTextField = "money";
ddList.DataBind();

<asp:DropDownList ID="ddList" Runat="Server">

Hope this helps,
Martha
"Srinivas" <an********@NO.JUNK.MAIL> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi,

My function returns a datareader object containing only one column of
datatype money. In asp.net I want to bind this datareader to a dropdownlist. Can anyone suggest me how to do this with some sample code if possible.

Thanks

Srinivas

Nov 18 '05 #3
Thanks

I have tried the code. Its working fine. But the amounts are displayed as
100.000 as the datatype of the column from which the data is retrieved is
money. Is there any way to display the value 100.000 as 100

Srinivas
"Martha[MSFT]" <ma******@online.microsoft.com> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
You can assign your reader to the DropDownList control's "DataSource"
property and call the DataBind() method. You must also set the
DropDownList's "DataTextField" property to the column that you want to bind to the control.
Here are some code pieces:

reader = command.ExecuteReader();
ddList.DataSource = reader;
ddList.DataTextField = "money";
ddList.DataBind();

<asp:DropDownList ID="ddList" Runat="Server">

Hope this helps,
Martha
"Srinivas" <an********@NO.JUNK.MAIL> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi,

My function returns a datareader object containing only one column of
datatype money. In asp.net I want to bind this datareader to a

dropdownlist.
Can anyone suggest me how to do this with some sample code if possible.

Thanks

Srinivas


Nov 18 '05 #4

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

Similar topics

0
by: DotNetJunkies User | last post by:
Hie, I create a dynamique HtmlTable, in each cell of this HtmlTable put a new control ( dropdownlist,label,..) and then want to create handler so that if i change the select item in the dop downlist...
12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
0
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
8
by: tshad | last post by:
Can you databind a dropdownlist to another dropdownlist? I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next...
2
by: Brent | last post by:
Here's my function: public void getInterestLevelDDL(string co_interest_level) { sql = ; //get_select_list creates a valid ICollection datatable ctrlDDL_CIL.DataSource =...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged method, refill DropDownList2 and set the focus to...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.