简体   繁体   English

vb.net选中了单选按钮

[英]vb.net selected radio button

I have the following radion button in VB.NET 我在VB.NET中有以下radion按钮

  <asp:RadioButtonList ID="rbedit" runat="server"  RepeatDirection="horizontal" >
        <asp:ListItem Value="1" >Yes</asp:ListItem>
        <asp:ListItem Value="0" >No</asp:ListItem>
   </asp:RadioButtonList></td>

I need to figure what button the user clicked on and then set a variable with that value. 我需要确定用户点击了什么按钮,然后设置一个具有该值的变量。 How would I go about doing this? 我该怎么做呢?

You can use rbedit.SelectedIndex to get which button user clicked and then set the variable accordingly. 您可以使用rbedit.SelectedIndex来获取用户单击的按钮,然后相应地设置变量。

If you want to get it client side then use following code : 如果您想获得客户端,请使用以下代码:

function getRadVal(radlist)
{
 if (document.forms['Form1'].elements[radlist])
 {  var radGrp = document.forms['Form1'].elements[radlist];
  var radGrpValue = '0';
  for (var i = 0; i < radGrp.length; i++) 
      if (radGrp[i].checked) {
          radGrpValue = radGrp[i].value;
                break;
      } 
  return radGrpValue;
 }
 else
  return '';
}

to call this use : // Get Value of RadioButtonList 调用此用法://获取RadioButtonList的值

var myValue=getRadVal('rbedit'); var myValue = getRadVal('rbedit');

在按钮事件处理程序中使用rbedit.selectedvalue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM