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

Top 5 Contributors of the Month

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to bind List to List box and dropdown list

Posted By:shankey       Posted Date: February 07, 2011    Points: 40    Category: Collections    URL: http://www.dotnetspark.com  

How to bind List to List box and dropdown list

How to bind List to List box and dropdown list

This tutorial will let you learn how to bind List to the listbox/dropdown list. Following are some simple steps to bind your listbox/dropdown list to List.

Step 1

Create a List in you code behind file i.e .CS file. Following code shows how the List of string is created. Months is a List which stores a list of months in a year.
///Creating List of string for months.
  public static List<string> Months = new List<string> { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };

Step 2

After creating List, It's the time to bind List with your listbox/dropdown list. Following code binds to dropdown and listbox too.
//Binding list of string to listbox
  lst.DataSource = Months;
  //Binding list of string to dropdown list
  drp.DataSource = Months;


Further Readings:


No response found. Be the first to respond this post

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