<asp:RadioButtonList id="rdWenHua" runat="server" Width="164px" RepeatColumns="3" Height="1px" RepeatDirection="Horizontal"
CellSpacing="1" CellPadding="1">
<asp:ListItem Value="小学">小学</asp:ListItem>
<asp:ListItem Value="初中">初中</asp:ListItem>
<asp:ListItem Value="高中">高中</asp:ListItem>
<asp:ListItem Value="大学" Selected="True">大学</asp:ListItem>
<asp:ListItem Value="硕士">硕士</asp:ListItem>
<asp:ListItem Value="博士">博士</asp:ListItem>
</asp:RadioButtonList>
用下面代码取值,不管RadioButtonList选中的是哪项,得到的都是“大学”,怎么回事?
private void btnAdd_Click(object sender, System.EventArgs e)
{
Response.Write (rdWenHua.SelectedValue);
}
CellSpacing="1" CellPadding="1">
<asp:ListItem Value="小学">小学</asp:ListItem>
<asp:ListItem Value="初中">初中</asp:ListItem>
<asp:ListItem Value="高中">高中</asp:ListItem>
<asp:ListItem Value="大学" Selected="True">大学</asp:ListItem>
<asp:ListItem Value="硕士">硕士</asp:ListItem>
<asp:ListItem Value="博士">博士</asp:ListItem>
</asp:RadioButtonList>
用下面代码取值,不管RadioButtonList选中的是哪项,得到的都是“大学”,怎么回事?
private void btnAdd_Click(object sender, System.EventArgs e)
{
Response.Write (rdWenHua.SelectedValue);
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>CSharpTemp</title>
<meta name=vs_defaultClientScript content="JavaScript">
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write (rdWenHua.SelectedValue);
} </script> </head>
<body>
<form id="Form1" method="post" runat="server">
<asp:RadioButtonList id="rdWenHua" runat="server" Width="164px" RepeatColumns="3" Height="1px" RepeatDirection="Horizontal"
CellSpacing="1" CellPadding="1">
<asp:ListItem Value="小学">小学</asp:ListItem>
<asp:ListItem Value="初中">初中</asp:ListItem>
<asp:ListItem Value="高中">高中</asp:ListItem>
<asp:ListItem Value="大学" Selected="True">大学</asp:ListItem>
<asp:ListItem Value="硕士">硕士</asp:ListItem>
<asp:ListItem Value="博士">博士</asp:ListItem>
</asp:RadioButtonList>
<asp:Button id="Button1" runat="server" Text="测试按钮"/>
</form>
</body>
</html>
这样如何