Monday, March 21, 2011

Populating TimeZone list in ASP.Net

Following code will populate the controls in asp.net:

//Populating in DropDownList (1)
this.DropDownList1.DataSource = TimeZoneInfo.GetSystemTimeZones();
this.DropDownList1.DataBind();

//Populating in DropDownList (2)
foreach (TimeZoneInfo tmz in TimeZoneInfo.GetSystemTimeZones())
{
this.DropDownList1.Items.Add(new ListItem(tmz.DisplayName, tmz.Id));
}
//Populating in GridView
GridView1.DataSource = TimeZoneInfo.GetSystemTimeZones();
GridView1.DataBind();

No comments:

Post a Comment