Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Bind a SQL table to a dropdownlist at design time? Surely it can be done?

Reply
Thread Tools

Bind a SQL table to a dropdownlist at design time? Surely it can be done?

 
 
GG
Guest
Posts: n/a
 
      05-24-2005
I have a typical ASP page with a dropdownlist web form control. I want
this to auto-populate from a column in a sql table.

I've tried dragging a sql connection data control onto the form, played
with data binding, everything! I'm sure this is easy, can anyone point
out the steps I need to take?

Thanks ...

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      05-24-2005
Here's an example:

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection cn = new SqlConnection("server=localhost;database=pubs;trus ted_connection=yes;"))
{
using (SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "select * from authors";
cn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
_ddl1.DataSource = rdr;
_ddl1.DataTextField = "au_fname";
_ddl1.DataBind();
}
}
}
}
</script>
<body>
<form id="form1" runat="server" >
<aspropDownList runat="server" ID="_ddl1"></aspropDownList>
</form>
</body>
</html>


-Brock
DevelopMentor
http://staff.develop.com/ballen



> I have a typical ASP page with a dropdownlist web form control. I want
> this to auto-populate from a column in a sql table.
>
> I've tried dragging a sql connection data control onto the form,
> played with data binding, everything! I'm sure this is easy, can
> anyone point out the steps I need to take?
>
> Thanks ...
>




 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWF2ZXJpY2s=?=
Guest
Posts: n/a
 
      05-25-2005
Hi!

Dude, hope that u can get the values in a DataSet from the DataBase.Now
things are pretty starightfwd from here
just put in this code


if(objDs.Tables.Count != 0) //objDs is the dataset which has the table
Employee
{
if(objDs.Tables[0].Rows.Count != 0)
{
ddlEmployeeId.DataSource = objDs;
ddlEmployeeId.DataValueField = "EmployeeID";
ddlEmployeeId.DataTextField = "EmpName";
ddlEmployeeId.DataBind();
}
}




"GG" wrote:

> I have a typical ASP page with a dropdownlist web form control. I want
> this to auto-populate from a column in a sql table.
>
> I've tried dragging a sql connection data control onto the form, played
> with data binding, everything! I'm sure this is easy, can anyone point
> out the steps I need to take?
>
> Thanks ...
>
>

 
Reply With Quote
 
mail2saion mail2saion is offline
Junior Member
Join Date: May 2009
Posts: 2
 
      05-14-2009
Hello readers today i found a helpful post on how you can optimize your code to bind with Dropdown List:

shawpnendu.blogspot.com/2009/05/how-to-bind-or-populate-data-into.html

HOPE IT WILL HELP READERS.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using cout to print hex values; surely you can't be serious Chris Stankevitz C++ 13 02-21-2012 11:08 AM
how to create dnamic treeview in asp.net 2.0 bind with sql server 2005 table das ASP .Net 2 04-24-2006 03:39 PM
Dropdownlist add default blank while bind to sql server syncwa ASP .Net 3 02-14-2006 03:14 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
RMI Server Stub. Must be run interactively? Surely not! Andoni Java 0 04-26-2004 11:23 AM



Advertisments