How to populate dropdown list from database?

G

Guest

I saw an example of this which talked about assigning valueTextField and
DataTextField. So I have twenty items coming back from the database(I use a
dataadapter), do I need to go thru a loop to assign each item in the Dropdown?
Is there a way to just assign the datasource to a dataset (that's filled
with data)?

Thanks a lot

Merdaad
 
L

Luis Esteban Valencia

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
 
L

Luis Esteban Valencia

private void cargarProveedores()

{

SqlDataAdapter myadapter = new SqlDataAdapter("select idproveedor,
nombreproveedor from proveedores order by nombreproveedor asc",
sqlConnection1);

DataSet myds = new DataSet();

myadapter.Fill(myds);

comboproveedores.DataSource= myds;

comboproveedores.DataTextField ="nombreproveedor";

comboproveedores.DataValueField = "idproveedor";

comboproveedores.DataBind();

}
 
G

Guest

Thanks that worked great.

Luis Esteban Valencia said:
private void cargarProveedores()

{

SqlDataAdapter myadapter = new SqlDataAdapter("select idproveedor,
nombreproveedor from proveedores order by nombreproveedor asc",
sqlConnection1);

DataSet myds = new DataSet();

myadapter.Fill(myds);

comboproveedores.DataSource= myds;

comboproveedores.DataTextField ="nombreproveedor";

comboproveedores.DataValueField = "idproveedor";

comboproveedores.DataBind();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top