Click here to Skip to main content
12,559,073 members (39,891 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
                <td align="center" class="style1">
                    <asp:Label runat="server" ID="Role" Text="Role">
                    <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Role"
                        DataValueField="ID" onselectedindexchanged="DropDownList1_SelectedIndexChanged">

In my deisgn i kept one drop down for role and i m maintaining a database table as ROLEID in that table contains two columns ID, ROLE. by default i gaved some roles as 1 Admin, 2 Leader 3 Manager so what is my question is how to bind the table to drop down list
Posted 9-Jan-13 19:57pm
Updated 9-Jan-13 20:36pm
Krunal Rohit 10-Jan-13 2:12am
Your question is not clear, elaborate it :)
Milind_T 10-Jan-13 2:20am
Write some proper subject and whatever written in subject, move to the question. Use "Improve Question" widget.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

protected void Page_Load(object sender, EventArgs e)
protected void bindDropDownList()
string constr = ConfigurationManager.ConnectionStrings["yourConnectionString"].ToString();         
SqlConnection con =new SqlConnection (constr);
SqlCommand com=new SqlCommand ("select * from ROLEID",con); 
SqlDataAdapter da=new SqlDataAdapter(com);
DataSet ds = new DataSet (); 
DropDownList1.DataTextField = ds.Tables[0].Columns["ROLE"].ToString();         DropDownList1.DataValueField=ds.Tables[0].Columns["ID"].ToString();

Remember that you should use stored procedure in place of direct query.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I think you are a beginner and need ADO.Net knowledge first.
Please go through the basics of .Net development.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161026.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100