CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Skip Navigation LinksHome » CodeDigest » Bind Generic List collection to DropDownList Control in ASP.Net   You are not logged in.
Search
 

Sponsored Links
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Bind Generic List collection to DropDownList Control in ASP.Net
Bind Generic List collection to DropDownList Control in ASP.Net
Submitted By Satheesh Babu B
On 12/2/2008 7:21:16 AM
Tags: ASP.Net,CodeDigest  

Bind Generic List collection to DropDownList Control in ASP.Net

Below code snippet will help to bind a generic list to dropdownlist control.


        List<Categories> _listCat = new List<Categories>();


        Categories _cat = new Categories();
        _cat.CategoryID = "1";
        _cat.Category = "C#";
        _listCat.Add(_cat);


        _cat = new Categories();
        _cat.CategoryID = "2";
        _cat.Category = "ASP.Net";
        _listCat.Add(_cat);


        _cat = new Categories();
        _cat.CategoryID = "1";
        _cat.Category = "VB.Net";
        _listCat.Add(_cat);


        ddlCategory.DataSource = _listCat;
        ddlCategory.DataTextField = "Category";
        ddlCategory.DataValueField = "CategoryID";
        ddlCategory.DataBind();

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..