aspx:
<asp:DropDownList runat="server" ID="ddlTimeZone" DataSource ="<%# TimeZoneInfo.GetSystemTimeZones().ToDictionary(z => z.DisplayName)%>" DataTextField="Key" DataValueField="Value">`
html:
<select name="ctl00$MainContent$ddlTimeZone" id="MainContent_ddlTimeZone">
<option value="(UTC-12:00) International Date Line West">(UTC-12:00) International Date Line West</option>
<option value="(UTC-11:00) Midway Island, Samoa">(UTC-11:00) Midway Island, Samoa</option>
<option value="(UTC-10:00) Hawaii">(UTC-10:00) Hawaii</option>
<option value="(UTC-09:00) Alaska">(UTC-09:00) Alaska</option>
<option value="(UTC-08:00) Pacific Time (US & Canada)">(UTC-08:00) Pacific Time (US & Canada)</option>
<option value="(UTC-08:00) Tijuana, Baja California">(UTC-08:00) Tijuana, Baja California</option>
<option value="(UTC-07:00) Arizona">(UTC-07:00) Arizona</option>
<option value="(UTC-07:00) Chihuahua, La Paz, Mazatlan">(UTC-07:00) Chihuahua, La Paz, Mazatlan</option>
当我尝试获取 ddlTimeZone.SelectedValue 时,我总是得到null(或-1,我不记得), SelectedItem 总是等于null。
答案 0 :(得分:1)
我明白了。它一直是
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
DataBind();
}