In the following example, I will show you how to get all the system timezones and bind them to a dropdownlist in Asp.net.
Step-1: Add a dropdownlist to your webpage. Lets its ID is "ddlTimeZone".
Step-2: Add 'using System.Collections.ObjectModel;' namespace to the .aspx.cs page.
Step-3: ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); returns all the TimeZones.
Write the following method to select all the Time Zones and bind them to dropdownlist.
Step-1: Add a dropdownlist to your webpage. Lets its ID is "ddlTimeZone".
Step-2: Add 'using System.Collections.ObjectModel;' namespace to the .aspx.cs page.
Step-3: ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); returns all the TimeZones.
Write the following method to select all the Time Zones and bind them to dropdownlist.
public void
GetTimeZones()
{
ReadOnlyCollection<TimeZoneInfo>
timeZones = TimeZoneInfo.GetSystemTimeZones();
ddlTimeZone.DataSource = timeZones;
ddlTimeZone.DataBind();
ddlTimeZone.Items.Insert(0, "Select");
}
Step-4: Call this method wherever you need to bind the dropdown.
OUTPUT:
Your valuable comments will be highly appreciable.
Regards,
Prajanuranjan....
No comments:
Post a Comment