紫水晶编程技术论坛 - 努力打造成全国最好的编程论坛

 找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 2562|回复: 1

[开源] c# RadioButton 遍历

[复制链接]

1214

主题

1566

帖子

11

精华

管理员

菜鸟

Rank: 125Rank: 125Rank: 125Rank: 125Rank: 125

积分
93743

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2020-2-26 20:03:51 | 显示全部楼层 |阅读模式
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6.     <title></title>
  7. </head>
  8. <body>
  9.     <form id="form1" runat="server">
  10.     <asp:Panel ID="Panel1" runat="server" Height="220px">
  11.         <asp:RadioButton ID="RadioButton1" runat="server" BorderStyle="Groove" Checked="True" GroupName="a1" Text="aaaaaaaaaaaaaa" Width="298px" />
  12.         <br />
  13.         <asp:RadioButton ID="RadioButton2" runat="server" BorderStyle="Groove" GroupName="a1" Height="28px" Text="bbbbbbbbbbbbbb" Width="297px" />
  14.         <br />
  15.         <asp:RadioButton ID="RadioButton3" runat="server" BorderStyle="Groove" GroupName="a1" Text="cccccccccccccc" Width="292px" />
  16.         <br />
  17.         <asp:TextBox ID="TextBox1" runat="server" Height="19px" Width="148px"></asp:TextBox>
  18.         <br />
  19.         <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
  20.     </asp:Panel>
  21.     </form>
  22. </body>
  23. </html>
复制代码



  1.        protected void Button1_Click(object sender, EventArgs e)
  2.         {

  3.             foreach (Control c in this.Panel1.Controls) //遍历这个控件组;
  4.             {

  5.                 if (c is RadioButton) //如果是单选按钮
  6.                 {
  7.                     if (((RadioButton)c).Checked == true) //如果此单选按钮已被选中
  8.                     {
  9.                         TextBox1.Text = ((RadioButton)c).Text;
  10.                     }
  11.                 }
  12.             }
  13.         }
  14.       
复制代码

20

主题

86

帖子

0

精华

管理员

Rank: 125Rank: 125Rank: 125Rank: 125Rank: 125

积分
1653
发表于 2020-10-9 13:46:09 | 显示全部楼层
顶一下。阿杰好久不见!
我是管理员,虽然不常吭声,但无时无刻关注着论坛里每个人的一举一动!
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

手机版|Archiver|紫水晶工作室 ( 粤ICP备05020336号 )

GMT+8, 2024-4-16 18:46 , Processed in 0.024637 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表