asp.net中怎样取得一组radiobutton的选中项的值 10
我想实现这样的功能:有四个单选按钮,点击其一获取它的值,并储存到一个变量中有没有简单一点的方法,能不能通过一组RadioButton的GroupName取得value呢(...
我想实现这样的功能:有四个单选按钮, 点击其一 获取它的值,并储存到一个变量中
有没有简单一点的方法,能不能通过一组RadioButton的GroupName取得value呢(不需要写四个方法,太复杂) 展开
有没有简单一点的方法,能不能通过一组RadioButton的GroupName取得value呢(不需要写四个方法,太复杂) 展开
2个回答
展开全部
下闷悔面是我的测试代码:
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" %>
<!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" >
<head runat="server">
<title>无标题谨罩迹页</title>
</head>
<body>
<% Response.Write("你好1"+DateTime.Now); %>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Height="92px" Text="Label" Width="308px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="68px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
Width="54px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="test" OnCheckedChanged="RadioButton1_CheckedChanged" Text="1" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="test" OnCheckedChanged="RadioButton2_CheckedChanged" Text="2" />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="test" OnCheckedChanged="RadioButton3_CheckedChanged" Text="3" />
</div>
</form>
</body>
</html>
你可以用javascript实现,我不知道你想要什么样的方法
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" %>
<!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" >
<head runat="server">
<title>无标题谨罩迹页</title>
</head>
<body>
<% Response.Write("你好1"+DateTime.Now); %>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Height="92px" Text="Label" Width="308px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="68px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
Width="54px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="test" OnCheckedChanged="RadioButton1_CheckedChanged" Text="1" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="test" OnCheckedChanged="RadioButton2_CheckedChanged" Text="2" />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="test" OnCheckedChanged="RadioButton3_CheckedChanged" Text="3" />
</div>
</form>
</body>
</html>
你可以用javascript实现,我不知道你想要什么样的方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是POST实现么?还是用js实现?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询