zoukankan      html  css  js  c++  java
  • RadioButton控件

    前台代码:

    1 <div>
    2     <asp:RadioButton ID="RadioButton1" runat="server" GroupName ="sex" Text =""/>
    3     <asp:RadioButton ID="RadioButton2" runat="server" GroupName ="sex"  Text =""/>
    4     <asp:Button ID="Button1" runat="server" Text="Button" OnClick ="Button1_Click"/>
    5     <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    6 </div>

    *其中,groupName要写上,这个的作用是让其属于同一个组,选了一个,不能选另一个。

    后台代码:

     1 /// <summary>
     2 /// Button1按钮的单机事件
     3 /// </summary>
     4 /// <param name="sender"></param>
     5 /// <param name="e"></param>
     6 protected void Button1_Click(object sender, EventArgs e)
     7 {
     8     string s = string.Empty;
     9 
    10     if (RadioButton1.Checked)
    11     {
    12         s += RadioButton1.Text;
    13     }
    14     if (RadioButton2.Checked)
    15     {
    16         s += RadioButton2.Text;
    17     }
    18 
    19     this.Label1.Text = "您选择的是:" + s;
    20 }

    最终效果:

    上面就是RadioButton控件的使用方法。

  • 相关阅读:
    微信成为开发者C#代码
    Ajax.ActionLink()方法的使用
    Entity FrameWork初始化数据库的四种策略
    最长公共子序列
    表达式求值
    韩信点兵
    蛇形填数
    5个数求最值
    求转置矩阵问题
    素数求和问题
  • 原文地址:https://www.cnblogs.com/KTblog/p/4272995.html
Copyright © 2011-2022 走看看