473,782 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1426
I found it best to load them in functions such as below.

public static void Loadlist(DropDo wnList thisDropDownLis t , SqlDataReader
dr)
{
thisDropDownLis t.Items.Clear() ;
ListItem li;
while(dr.Read() )
{
li = new ListItem(dr[1].ToString().Tri m(),dr[0].ToString().Tri m());
thisDropDownLis t.Items.Add(li) ;
}
dr.Close();
}

"Srinivas" <an********@NO. JUNK.MAIL> wrote in message
news:e#******** ******@TK2MSFTN GP09.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 "DataTextFi eld" property to the column that you want to bind
to the control.
Here are some code pieces:

reader = command.Execute Reader();
ddList.DataSour ce = reader;
ddList.DataText Field = "money";
ddList.DataBind ();

<asp:DropDownLi st ID="ddList" Runat="Server">

Hope this helps,
Martha
"Srinivas" <an********@NO. JUNK.MAIL> wrote in message
news:e%******** ********@TK2MSF TNGP09.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******@onlin e.microsoft.com > wrote in message
news:e5******** ******@TK2MSFTN GP11.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 "DataTextFi eld" property to the column that you want to bind to the control.
Here are some code pieces:

reader = command.Execute Reader();
ddList.DataSour ce = reader;
ddList.DataText Field = "money";
ddList.DataBind ();

<asp:DropDownLi st ID="ddList" Runat="Server">

Hope this helps,
Martha
"Srinivas" <an********@NO. JUNK.MAIL> wrote in message
news:e%******** ********@TK2MSF TNGP09.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
1669
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 i change the text displayed in the label in the same row. hier is my code: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web;
12
2807
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 Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
0
4794
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 TemplateColumn with a DropDownList (DDL) in the FooterItemTemplate that is populated in the Page_Load event using a Sub Routine as the DataSource of the DDL. The FooterItemTemplate's DDL populates as expected when the DataGrid's DataBind method is called. ...
8
1675
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 as the dataReader can only be read once. I tried: ExperienceLevel.DataSource=dbReader ExperienceLevel.DataTextField= "Description"
2
3145
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 = tools.get_select_list(sql);
11
5815
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
4
6140
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 extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
2
9959
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
3834
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 DropDownList1 using the ScriptManager SetFocus method. Use the Visual Studio debugger. Set a breakpoint on in the (!IsPostBack) part of the PageLoad method. Start the web application and continue after the breakpoint has been reached.
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.