Bind Generic List to ASP.NET DropDownBox (or GridView)

//Class for generic list
public class MarketDates
{
    public string DisplayDate { get; set; }
    public string SelectDate { get; set; }
}

 //List for binding
List LstFromDate = new List();
List LstToDate = new List();

//Load List
for (int i = 1999; i < (DateTime.Now.Year + 1); i++)
{
   MarketDates DDLFromDate = new MarketDates();
   MarketDates DDLToDate = new MarketDates();

   DDLFromDate.DisplayDate = "JAN-" + i.ToString();
   DDLFromDate.SelectDate = i.ToString();
   LstFromDate.Add(DDLFromDate);

   DDLToDate.DisplayDate = "DEC-" + i.ToString();
   DDLToDate.SelectDate = i.ToString();
   LstToDate.Add(DDLToDate);
}

//Bind
DDLFromYear.DataTextField = "DisplayDate";
DDLFromYear.DataValueField = "SelectDate";
DDLFromYear.DataSource = LstFromDate;
DDLFromYear.DataBind();
     
DDLToYear.DataTextField = "DisplayDate";
DDLToYear.DataValueField = "SelectDate";
DDLToYear.DataSource = LstToDate;
DDLToYear.DataBind();  
Comments are closed