Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
<tr>
                <td align="center" class="style1">
                    <asp:Label runat="server" ID="Role" Text="Role">
                    </asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Role"
                        DataValueField="ID" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
 
                    </asp:DropDownList>
                </td>
            </tr>
 

 
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
Edited 9-Jan-13 20:36pm
v5
Comments
Krunal Rohit at 10-Jan-13 2:12am
   
Your question is not clear, elaborate it :)
Milind_T at 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
good
Please Sign up or sign in to vote.

Solution 1

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
bindDropDownList();
}
protected void bindDropDownList()
{
string constr = ConfigurationManager.ConnectionStrings["yourConnectionString"].ToString();         
SqlConnection con =new SqlConnection (constr);
con.Open();
SqlCommand com=new SqlCommand ("select * from ROLEID",con); 
SqlDataAdapter da=new SqlDataAdapter(com);
DataSet ds = new DataSet (); 
da.Fill(ds);  
DropDownList1.DataTextField = ds.Tables[0].Columns["ROLE"].ToString();         DropDownList1.DataValueField=ds.Tables[0].Columns["ID"].ToString();
DropDownList1.DataSource=ds.Tables[0];
DropDownList1.DataBind();      
}
 
Remember that you should use stored procedure in place of direct query.
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 225
1 Manfred R. Bihy 190
2 CHill60 180
3 _Amy 155
4 OriginalGriff 150
0 OriginalGriff 7,320
1 Sergey Alexandrovich Kryukov 6,043
2 Maciej Los 3,754
3 Peter Leow 3,448
4 CHill60 2,572


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
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