dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersRakesh Chaubey
Mohamed Rifayee
sp
srisunny
Sidharthan
naveensanagasetti
pragna
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » Databinding

Bind DropDownList from DataBase , Using c#


Posted Date:     Category: Databinding    
Author: Member Level: Silver    Points: 3



 


The following code shows how to bind a DropDownList control with data from a table in the DataBase.


string s = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

private void bindtoddl()
{
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("select FieldName from TableName", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "FieldName"; // FieldName of Table in DataBase
DropDownList1.DataValueField = "FieldName";
DropDownList1.DataBind();

}








Did you like this resource? Share it with your friends and show your love!


Responses to "Bind DropDownList from DataBase , Using c#"
Author: Ankit Bhadana    17 Oct 2008Member Level: Bronze   Points : 1
sry Suresh! this code is not working for me,,,i still cant bind data from my database to the dropdownlist in my application using this code.On runing the code ,,it still shows an empty dropdownlist.


Author: Shawpnendu bikash maloroy    14 May 2009Member Level: Silver   Points : 1
READERS YOU CAN VISIT MY BELOW POST WHERE I TRIED SIMPLIFY THE CODE FOR REUSABILITY.

http://shawpnendu.blogspot.com/2009/05/how-to-bind-or-populate-data-into.html

HOPE IT WILL HELP YOU A LOT.

REGARDS
http://shawpnendu.blogspot.com



Guest Author: dhj     20 Jul 2012
its isnt working for me tooo


Guest Author: rajesh     28 Feb 2013
Gud mnr sir
i want to retrive data from database to dropdown list
here mainly i want by selecting which element on first dropdown list that element particular elements must display in second dropdown list in c# pls tell how plssssssssss



Guest Author: Sujitha     06 Mar 2013
Hai,
I want to retrive data from database to dropdown list.
then .. if i select the options in first dropdown list,i want to display the related sub options in the second & 3rd dropdownlist..ex : country,state city.. i'm a new for this, so i need a clear & detail coding with explanation....please help me



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Fill a DropDownList with files in a directory using c#
    Previous Resource: How To bind data With the help odbc by coding
    Return to Resources
    Post New Resource
    Category: Databinding


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.