|
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:Panel ID="Panel1" runat="server" Height="220px">
- <asp:RadioButton ID="RadioButton1" runat="server" BorderStyle="Groove" Checked="True" GroupName="a1" Text="aaaaaaaaaaaaaa" Width="298px" />
- <br />
- <asp:RadioButton ID="RadioButton2" runat="server" BorderStyle="Groove" GroupName="a1" Height="28px" Text="bbbbbbbbbbbbbb" Width="297px" />
- <br />
- <asp:RadioButton ID="RadioButton3" runat="server" BorderStyle="Groove" GroupName="a1" Text="cccccccccccccc" Width="292px" />
- <br />
- <asp:TextBox ID="TextBox1" runat="server" Height="19px" Width="148px"></asp:TextBox>
- <br />
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
- </asp:Panel>
- </form>
- </body>
- </html>
复制代码
- protected void Button1_Click(object sender, EventArgs e)
- {
- foreach (Control c in this.Panel1.Controls) //遍历这个控件组;
- {
- if (c is RadioButton) //如果是单选按钮
- {
- if (((RadioButton)c).Checked == true) //如果此单选按钮已被选中
- {
- TextBox1.Text = ((RadioButton)c).Text;
- }
- }
- }
- }
-
复制代码 |
|