c#中如何获取Radiobutton的值

c#中如何获取Radiobutton的值,第1张

应该是用“RadioButtonList ”,

ASPX

<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"

RepeatDirection="Horizontal" RepeatLayout="Flow">

<asp:ListItem Value="True">男</asp:ListItem>

<asp:ListItem Value="False">女</asp:ListItem>

</asp:RadioButtonList>

CS

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)

{

bool sex = ConvertToBoolean(RadioButtonList1SelectedValue);

}

 //aspx页面

 <asp:RadioButton ID="RadioButton1" runat="server" GroupName="testGroup" Checked="true" Text="RadioButton1"/>

  <asp:RadioButton ID="RadioButton2" runat="server" GroupName="testGroup" Text="RadioButton2"/>

  

  //cs页面:使用Checked属性做判断

          if (RadioButton1Checked)

            {

                //选择RadioButton1

            }

            else

            {

                //选择RadioButton1

            }

Protected void Page_Load(ByVal sender As Object, ByVal e As SystemEventArgs)

{

RadioButton1AutoPostBack = True; //让RadioButton响应服务端事件

RadioButton2AutoPostBack = True;

}

Protected void RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As SystemEventArgs)

{

变量 = 0;

}

Protected void RadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As SystemEventArgs)

{

变量 = 1;

}

下面是我的测试代码

Defaultaspxcs的代码如下:

using System;

using SystemConfiguration;

using SystemWeb;

using SystemWebSecurity;

using SystemWebUI;

using SystemWebUIWebControls;

using SystemWebUIWebControlsWebParts;

using SystemWebUIHtmlControls;

using SystemNet;

public partial class _Default : SystemWebUIPage

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

SystemWeb>

可以通过RadioButtonList1SelectedItemtoString()来获取值,还可以访问RepeatColumns和RepeatDirection属性。可以直接把控件绑定到数据源控件提供的条目上。

<form name="form1" method="post" action="indexasp">

<input name="sex" type="radio" value="男" checked>

<input type="radio" name="sex" value="女">

<input type="submit" name="Submit" value="提交">

</form>

indexasp

sex=trim(request("sex"))'这里就是获取单选按钮的值

你的radio在form里,并且有submit按钮吗?比如:

<form action="defaultaspx" method="post" name="frm">

<input type="radio" name="dao_name" value="<%=daotu%>" onclick="alert(thisvalue);" />

<input type="submit" />

浏览器中按submit按钮后,然后在defaultaspx中才可以访问RequestForm["dao_name"]

其实这不是ASPNET的风格,应该用服务器控件RadioButton

Sorry!我写错了,是RadioButton ,不是RadioBox

我的意思是:

看到你代码中radio标记的value是用服务器代码取得的,而且还要传递值回服务器,并不是完全在客户端工作。

所以,直接放上一个RadioButton服务器控件,设置为AutoPostBack,在CheckedChanged事件中编写cmdCommandText = "yponguou"

cmdExecute,array(a,name) 等代码。

利用事件机制,才是ASPNET的风格。

div id="wrap">

<input type="radio" name="payMethod" value="1" />支付宝

<input type="radio" name="payMethod" value="2" />财务通

</div>

获取一组单选按钮对象:var obj_payPlatform = $('#wrap input[name="payMethod"]');

获取被选中按钮的值 :var val_payPlatform = $('#wrap input[name="payMethod"]:checked ')val();

以上就是关于c#中如何获取Radiobutton的值全部的内容,包括:c#中如何获取Radiobutton的值、asp.net 一个radiobutton组,怎么得到选择的那个值、asp.net radiobutton 获取值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/9422038.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存