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

populate DropDownList from DB

Hi,
Could someone tell me how can be populated DropdownList from Data Base. I
use ASP.NET/C#/MS SQL SERVER.

Thanks!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.
Nov 18 '05 #1
11 3884
Victor,

You need to get the database data into a dataset, set the DropdownList
properties DataSource to the dataset name and DataMember to the table name
and call DataBind method.

Eliyahu

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:OM*************@TK2MSFTNGP12.phx.gbl...
Hi,
Could someone tell me how can be populated DropdownList from Data Base. I
use ASP.NET/C#/MS SQL SERVER.

Thanks!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #2
Thanks for the reply!

Could you add the other code?

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter da = new SqlDataAdapter ("Select * FROM blek.TypeOffer ",
conn);
DataSet ds = new DataSet();

da.Fill (ds,"Table");

DropDownList2.DataSource = ds;


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 18 '05 #3
DropDownList2.DataMember = "Table";
DataBind (); // or DropDownList2.DataBind ();
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Thanks for the reply!

Could you add the other code?

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter da = new SqlDataAdapter ("Select * FROM blek.TypeOffer ",
conn);
DataSet ds = new DataSet();

da.Fill (ds,"Table");

DropDownList2.DataSource = ds;


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 18 '05 #4
Hi, Thanks again for the reply! I wrote that but it doesn't work. Could you
check for an error?

Thanks

private void Page_Load(object sender, System.EventArgs e)

{

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter da = new SqlDataAdapter ("Select * FROM blek.TypeOffer ",
conn);
DataSet ds = new DataSet();

da.Fill (ds,"Table");

DropDownList2.DataSource = ds;

DropDownList2.DataMember = "Table";

DropDownList2.DataBind () ;

}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.
Nov 18 '05 #5
see inline

"Viktor Popov" <vi****@yahoo.com> wrote in message news:O5**************@TK2MSFTNGP10.phx.gbl...
Hi, Thanks again for the reply! I wrote that but it doesn't work. Could you
check for an error?

Thanks

private void Page_Load(object sender, System.EventArgs e)

{

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter da = new SqlDataAdapter ("Select * FROM blek.TypeOffer ",
conn);
DataSet ds = new DataSet();

da.Fill (ds,"Table");

DropDownList2.DataSource = ds;

DropDownList2.DataMember = "Table";

DropDownList2.DataBind () ;

add the code (with the correct values):
DropDownList2.DataTextField = "<name of column for visible text>";
DropDownList2.DataValueField = "<name of column for internal value>";
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 18 '05 #6
I tryed to do that:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter da = new SqlDataAdapter ("Select * FROM blek.TypeOffer ",
conn);
conn.Open();
da.SelectCommand.ExecuteReader();
DataSet ds = new DataSet();
da.Fill (ds,"Table");
DropDownList2.DataSource = ds;
DropDownList2.DataMember = "Table";
DropDownList2.DataTextField = "TypeOffer";
DropDownList2.DataValueField = "OfferID";
DropDownList2.DataBind () ;]
}

but it doesn't work.
What could I do?

Thanks!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.
Nov 18 '05 #7
what's the error?

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
I tryed to do that:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter da = new SqlDataAdapter ("Select * FROM blek.TypeOffer ", conn);
conn.Open();
da.SelectCommand.ExecuteReader();
DataSet ds = new DataSet();
da.Fill (ds,"Table");
DropDownList2.DataSource = ds;
DropDownList2.DataMember = "Table";
DropDownList2.DataTextField = "TypeOffer";
DropDownList2.DataValueField = "OfferID";
DropDownList2.DataBind () ;]
}

but it doesn't work.
What could I do?

Thanks!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 18 '05 #8
There is no error. When I start the application the DropDownList is empty.
There are no values, no items. My table is full with data
TypeOffer
---------------------
OfferID TypeOffer
1 rent
2 sell
3 change

Do you know what's wrong?
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ea**************@TK2MSFTNGP09.phx.gbl...
what's the error?

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
I tryed to do that:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter da = new SqlDataAdapter ("Select * FROM
blek.TypeOffer ",
conn);
conn.Open();
da.SelectCommand.ExecuteReader();
DataSet ds = new DataSet();
da.Fill (ds,"Table");
DropDownList2.DataSource = ds;
DropDownList2.DataMember = "Table";
DropDownList2.DataTextField = "TypeOffer";
DropDownList2.DataValueField = "OfferID";
DropDownList2.DataBind () ;]
}

but it doesn't work.
What could I do?

Thanks!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.
Nov 18 '05 #9
Can set a breakpoint after the line with da.Fill (ds,"Table"); and check if
the dataset actually gets any data?

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
There is no error. When I start the application the DropDownList is empty.
There are no values, no items. My table is full with data
TypeOffer
---------------------
OfferID TypeOffer
1 rent
2 sell
3 change

Do you know what's wrong?
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ea**************@TK2MSFTNGP09.phx.gbl...
what's the error?

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
I tryed to do that:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter da = new SqlDataAdapter ("Select * FROM

blek.TypeOffer
",
conn);
conn.Open();
da.SelectCommand.ExecuteReader();
DataSet ds = new DataSet();
da.Fill (ds,"Table");
DropDownList2.DataSource = ds;
DropDownList2.DataMember = "Table";
DropDownList2.DataTextField = "TypeOffer";
DropDownList2.DataValueField = "OfferID";
DropDownList2.DataBind () ;]
}

but it doesn't work.
What could I do?

Thanks!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 18 '05 #10
It doesn't work....I'm stucked.....
My last code is this. When I RUN it there are no errors but the DropDownList
is not populated and the msg.Text=""
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter dad = new SqlDataAdapter ("SELECT blek.TypeOffer.OfferID,
blek.TypeOffer.TypeOffer FROM blek.TypeOffer", conn);
DataTable table=new DataTable();
conn.Open();
dad.Fill(table);
conn.Close();
DropDownList2.DataSource=table;
DropDownList2.DataValueField = "OfferID";
DropDownList2.DataTextField = "TypeOffer";
DropDownList2.DataBind ();
msg.Text = table.Rows.Count.ToString();
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.
Nov 18 '05 #11
DropDownList2.DataSource=table;

try: DropDownList2.DataSource=table.DefaultView;
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
It doesn't work....I'm stucked.....
My last code is this. When I RUN it there are no errors but the DropDownList is not populated and the msg.Text=""
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter dad = new SqlDataAdapter ("SELECT blek.TypeOffer.OfferID, blek.TypeOffer.TypeOffer FROM blek.TypeOffer", conn);
DataTable table=new DataTable();
conn.Open();
dad.Fill(table);
conn.Close();
DropDownList2.DataSource=table;
DropDownList2.DataValueField = "OfferID";
DropDownList2.DataTextField = "TypeOffer";
DropDownList2.DataBind ();
msg.Text = table.Rows.Count.ToString();
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 18 '05 #12

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

Similar topics

0
by: Jeff Johnson | last post by:
I'm trying to populate a DropDownList with two columns of data I'm receiving from a stored procedure. All the examples I've found so far have mentioned modifying the SQL and are written in VB. ...
2
by: Rui Macdonald | last post by:
What is wrong with this code to populate a DropDownList? Can somebody Help me? Tnx RMac ===================================================================================== WebForm.aspx.vb
1
by: mr2_93 | last post by:
Hi All, I am new to ASP.NET and I am looking for help with the dropdownlist data control. I wonder if someone could show me how to past the SelectedValue of a data-bind dropdownlist to...
2
by: bobbyc13 | last post by:
I am new to vb.net and am getting frustrated and cannot find a post on the subject. I have a usercontrol (.ascx) with a dropdownlist. on the selectedindexchanged event of the codebeside of the...
3
by: sweetpotatop | last post by:
Hi, I am try to populate a number of dropdownlist with the same item, for i = 1 to 5 dd = me.controls("dd" + Cstr(i)) itm = new listiem itm.text ="abc" itm.value ="aaa"
6
by: peerraghu | last post by:
hi i am developing website which is a online shoping i want to populate two dropdownlist, in which the first dropdownlist should place the list of a paticular product and the next dropdownlist...
1
by: sudip2008 | last post by:
When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm This breaks this line from working properly window.opener.document.forms...... How can...
0
by: mkidd | last post by:
Hi, I'm trying to build an online form using asp.net and vb.net for the code behind in Visual Studio 2005. I want to fill 3 fields in a FormView that's connected to one table (table1) with...
2
by: Aswanth | last post by:
Hi.. I'm using Asp.Net with C#.... I'm having One Dropdownlist control(Users_Details_DDL) in Default.aspx Page... i'm having one Stored Procedure (Get_User_Email) which will display the Data...
5
by: =?Utf-8?B?U2F0aXNo?= | last post by:
C#, ASP.NET Q: Have a formview, with a dropdownlist which is bound to a column. This dropdownlist has a datasource of DataSet type. Now my objective is, on Selection Changed of this DropdownList,...
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
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
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,...
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.