PC Review


Reply
Thread Tools Rate Thread

Add values to DropDownList menu from SQL

 
 
Slickuser
Guest
Posts: n/a
 
      7th Oct 2008
How can I bind my value to drop menu list from my SQL database.

COLOR: red will have select as red in drop down menu list.

Color:
red
orange
white
blue
green


<asp:gridview id="gridview1" runat="server"
autogeneratecolumns="False" >
<columns>
<asp:BoundField DataField="ID" HeaderText="NAME" />
<asp:templatefield headertext="Color">
<itemtemplate>
<asp:dropdownlist id="dropdownlist1" runat="server">
</asp:dropdownlist>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>



protected void Page_Load(object sender, EventArgs e)
{
gridview1.DataSource = getdataset();
gridview1.DataBind();
}

private DataSet getdataset()
{
//string connectionstring = "Data Source=localhost;Initial
Catalog=northwind;User ID=sa;password=";
//string query = "";
// sql statement remove
SqlConnection myconnection = new
SqlConnection(connectionstring);
SqlDataAdapter ad = new SqlDataAdapter(query, myconnection);
DataSet ds = new DataSet();
ad.Fill(ds);
return ds;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Convert DropDownList values to enum values Andy B. Microsoft ASP .NET 2 8th Jun 2009 08:05 PM
remember values in dropdownlist samuelberthelot@googlemail.com Microsoft ASP .NET 1 1st Mar 2006 01:01 PM
DropDownList selected values Dylan Mines Microsoft ASP .NET 1 3rd May 2005 04:56 PM
Displaying DropDownList values =?Utf-8?B?S2VubmV0aCBQ?= Microsoft ASP .NET 1 28th Dec 2004 10:13 AM
Setting values in an asp:dropdownlist Kerri Microsoft ASP .NET 1 10th Aug 2003 10:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 AM.