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

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

GG
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 ...

Nov 19 '05 #1
2 1645
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" >
<asp:DropDownList runat="server" ID="_ddl1"></asp:DropDownList>
</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 ...


Nov 19 '05 #2
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 ...

Nov 19 '05 #3

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

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
4
by: Eric | last post by:
I'm trying to reproduce the following table layout using CSS only and am having some trouble with it. I'd like them to look identical but I'm having trouble sizing the labels properly as it doesnt...
2
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
3
by: troy.forster | last post by:
I am sure this must be about the simplest thing to do. I can whip something off in 10 different languages and environments with no problem. But VisualStudio 2003 and ASP.NET is sooooo...
1
by: Patrik Zdarsa | last post by:
Hi, I'm try VS 2005 and need UPDATE database record in viewform, all working when every filed is type TextBox (html INPUT) but I need change one TextBox to Listbox or dropdownlist and read data...
4
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor...
3
by: sck10 | last post by:
Hello, I am trying to bind an arraylist to a FormView DropDownList control in the PreRender state. The error that I get is the following: Databinding methods such as Eval(), XPath(), and...
1
by: sweatha | last post by:
Hi Friends I have designed a form with 1 DropDownList box named “ddlShow_time”& the form name is “Default4.aspx”. Just like that, I have the database(SQL SERVER 2000) as Table Name: ShowTime...
2
by: akshalika | last post by:
Hi, I have a repeater control. it dynamically bind textbox or dropdown base on some condition. i want to bind required field validator dynamically for validate textbox or dropdown. here is my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.