我在 asp.net 中有一个 RadioButtonList。我正在尝试做一件简单的事情,即在更改列表中的单选按钮时显示或隐藏 div。但事件 OnSelectedIndexChanged 没有触发。我不明白原因。这是代码
<asp:RadioButtonList ID="CityStateZip" runat="server" ForeColor="#333300" AutoPostBack="true" RepeatDirection="Horizontal" Width="274px" CausesValidation="true" ValidationGroup="SchoolSearchGroup" OnSelectedIndexChanged="CityStateZip_SelectedIndexChanged">
<asp:ListItem Value="1" Text="City and State" />
<asp:ListItem Value="2" Text="Zip Code" />
</asp:RadioButtonList>
<div id="zipcodediv" runat="server" visible="false" style="margin-left:75px">
code.........
</div>
<div id="citystatediv" runat="server" style="margin-left:75px; width: 708px;">
code........
</div>
背后的代码
protected void CityStateZip_SelectedIndexChanged(Object sender,EventArgs e)
{
if (CityStateZip.SelectedValue == "1")
{
zipcodediv.Visible = false;
citystatediv.Visible = true;
}
if (CityStateZip.SelectedValue == "2")
{
citystatediv.Visible = false;
zipcodediv.Visible = true;
}
}