.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Binding DropdownList from DataBase in C#.net

Posted By:Naresh       Posted Date: March 01, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

If we want to bind the values for drop down list from database by getting a value from another drop down list box.
 

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Datasource=c:/m/student.mdb");           
con.Open();
OleDbCommand cmd = new OleDbCommand("select RollNo from Student_Details where region='" + this.DropDownList2.Selectedvalue.Text + "'", con);
dr = cmd.ExecuteReader();
this.DropDownList2.DataSource = dr;
this.DropDownList2.DataTextField = "RollNo";
this.DropDownList2.DataValueField = "RollNo";
this.DropDownList2.DataBind();
con.Close();

     

Further Readings:

Responses
Author: prakashrishu         Company URL: http://www.dotnetspark.com
Posted Date: April 14, 2010

thanks alot i just looking for this one

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend