asp.net中怎样取得一组radiobutton的选中项的值

来源:百度知道 编辑:UC知道 时间:2024/06/02 02:47:44
我想实现这样的功能:有四个单选按钮, 点击其一 获取它的值,并储存到一个变量中
有没有简单一点的方法,能不能通过一组RadioButton的GroupName取得value呢(不需要写四个方法,太复杂)

下面是我的测试代码:
Default.aspx.cs的代码如下:

using System;

using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

System.Web.HttpCookie hp = new HttpCookie("UserName", this.TextBox1.Text);
System.Web.HttpContext.Current.Response.Cookies.Add(hp);
this.Label1.Text = System.Web.HttpContext.Current.Response.Cookies.Get("UserName").Value;

}

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{