【发布时间】:2011-07-02 01:01:57
【问题描述】:
我有一个简单的 ASP.NET 表单,其中包含一个 DropDownList 和两个 RadioButtons(它们共享相同的 GroupName)。
在 DropDownList 的 SelectedIndexChanged 事件中,我在两个 RadioButtons 上设置了Checked=true。
它设置第二个 RadioButton 很好,但它不会检查第一个。我究竟做错了什么?
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication3._Default" %>
<!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">
<body>
<form id="form1" runat="server">
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl_Changed"
ID="ddl">
<asp:ListItem Text="Foo" />
<asp:ListItem Text="Bar" />
</asp:DropDownList>
<asp:RadioButton runat="server" ID="rb1" Text="Foo" GroupName="foobar" />
<asp:RadioButton runat="server" ID="rb2" Text="Bar" GroupName="foobar" />
</form>
</body>
</html>
protected void ddl_Changed(object sender, EventArgs e)
{
if (ddl.SelectedIndex == 0)
rb1.Checked = true; // <- Doesn't actually work
else
rb2.Checked = true;
}
【问题讨论】:
标签: asp.net radio-button