get data from database in dropdown list

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 3
Reputation: anjela is an unknown quantity at this point 
Solved Threads: 0
anjela anjela is offline Offline
Newbie Poster

get data from database in dropdown list

 
0
  #1
Feb 21st, 2007
i'm developing application in .net using c# that has 1 dropdown list .I want to take data in it .to show in list.please suggest me some help
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: get data from database in dropdown list

 
0
  #2
Feb 21st, 2007
select the info that you want into a datatable,
set the datatable as the datasource for the dropdown. call the databind function. and make sure you specify in the dropdown control which columns have correspond with the DataValueField and DataTextField
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 3
Reputation: anjela is an unknown quantity at this point 
Solved Threads: 0
anjela anjela is offline Offline
Newbie Poster

Re: get data from database in dropdown list

 
0
  #3
Feb 22nd, 2007
can u give code for the get data from database in dropdown list
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: get data from database in dropdown list

 
0
  #4
Feb 22nd, 2007
  1. <asp:SqlDataSource ID="sda_nw1" runat="server" ConnectionString='<%$ ConnectionStrings:NORTHWIND %> '
  2. SelectCommand="SELECT orders.customerid, ContactName, count(OrderID) as numorders FROM orders join customers on orders.CustomerID=Customers.CustomerID group by orders.customerid, ContactName order by ContactName"
  3. ProviderName="System.Data.SqlClient" OldValuesParameterFormatString="original_{0}">
  4. </asp:SqlDataSource>
  5.  
  6. <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sda_nw1" DataTextField="customerid"
  7. DataValueField="customerid">
  8. </asp:DropDownList><br />
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: sachingargava is an unknown quantity at this point 
Solved Threads: 0
sachingargava sachingargava is offline Offline
Newbie Poster
 
-1
  #5
20 Days Ago
please give me the source code to retieve data from database todropdownlist in c#.net
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 28
Reputation: sanch01r is an unknown quantity at this point 
Solved Threads: 2
sanch01r sanch01r is offline Offline
Light Poster
 
0
  #6
14 Days Ago
You can add data that is returned from a reader the same way you would programmatically add items to a combobox (combobox1.Items.Add(*Object to add to combobox*);

Here is a sample of code that I did a while ago, this reads all of the Columns on a particular table and adds it to a combobox.

  1. for (int i = 0; i < dr.FieldCount; i++)
  2. {
  3. Fields.Add(dr.GetName(i));
  4. comboBox1.Items.Add(dr.GetName(i));
  5.  
  6.  
  7. }
Last edited by sanch01r; 14 Days Ago at 4:48 pm.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC