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

2024-11-28 12:11:41
推荐回答(2个)
回答1:

下面是我的测试代码:
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)
{
string xxx = RadioButtonList1.SelectedItem.Value;
Response.Write(xxx);
this.Label1.Text = xxx;
this.TextBox1.Text = xxx;
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
string xxx = this.RadioButton1.Text;
this.Label1.Text = xxx;
this.TextBox1.Text = xxx;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
string xxx = this.RadioButton2.Text;
this.Label1.Text = xxx;
this.TextBox1.Text = xxx;
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
string xxx = this.RadioButton3.Text;
this.Label1.Text = xxx;
this.TextBox1.Text = xxx;
}
}
Default.aspx的代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页


<% Response.Write("你好1"+DateTime.Now); %>






Width="54px">
1
2
3
4










你可以用javascript实现,我不知道你想要什么样的方法

回答2:

是POST实现么?还是用js实现?