To display all the TimeZone information in the DropDownList write the aspx code as:
Output :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="44px" Width="184px">
</asp:DropDownList>
</div>
</form>
</body>
</html>
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.DataSource = TimeZoneInfo.GetSystemTimeZones();
DropDownList1.DataTextField = "DisplayName";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
}
}Output :

No comments:
Post a Comment