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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 685
1 Manas Bhardwaj 380
2 OriginalGriff 344
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,967
1 OriginalGriff 4,332
2 Peter Leow 3,699
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid