• 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控件的使用方法。

  • 相关阅读:
    分页系统
    ORM-数据处理
    Django的用法
    登录cookie写法
    MySQL数据库的安装创建
    前端弹框编写
    ADB常用指令
    Appium环境配置
    Jmeter中传递cookie值
    Jmeter从文件中读取参数值
  • 原文地址:https://www.cnblogs.com/KTblog/p/4272995.html
Copyright © 2020-2023  润新知