//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();
The cleanest example I have seen for this feature is by Sergey Akopov.
Sergey implement a jQuery example that works wonderfully! Here is the link to the article. I attached the ZIP file same code, which is on Sergey's site as well.
MaintainScroll.zip (3.01 kb)
Here is a link to a pure JavaScript example (older 2006). I have not tried it out but wanted to save the link as another example.