请教大虾指点指点 本人新手上路
点击提交 如何遍历RadioButton 并输出选中按钮的Text<table>
<tr>
<td>
<asp:DataList ID="ddlPreview" runat="server" Width="80%" Font-Size="12px">
<ItemStyle Wrap="False" />
<ItemTemplate>
<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 0px;">
<tr>
<td width="6%">
<asp:RadioButton ID="rbutn1" runat="server" GroupName="rb1" Text="A"/>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn2" runat="server" GroupName="rb1" Text="B"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn3" runat="server" GroupName="rb1" Text="C"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn4" runat="server" GroupName="rb1" Text="D"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn5" runat="server" GroupName="rb2" Text="A"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn6" runat="server" GroupName="rb2" Text="B"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn7" runat="server" GroupName="rb2" Text="C"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn8" runat="server" GroupName="rb2" Text="D"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn9" runat="server" GroupName="rb3" Text="A"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn10" runat="server" GroupName="rb3" Text="B"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn11" runat="server" GroupName="rb3" Text="C"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn12" runat="server" GroupName="rb3" Text="D"//>
</td>
<td>
<asp:RadioButton ID="rbutn13" runat="server" GroupName="rb4" Text="A"//>
</td>
<td>
<asp:RadioButton ID="rbutn14" runat="server" GroupName="rb4" Text="B"//>
</td>
<td>
<asp:RadioButton ID="rbutn15" runat="server" GroupName="rb4" Text="C"//>
</td>
<td>
<asp:RadioButton ID="rbutn16" runat="server" GroupName="rb4" Text="D"//>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td><asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="提 交" /></td>
</tr>
</table>
点击提交 如何遍历RadioButton 并输出选中按钮的Text<table>
<tr>
<td>
<asp:DataList ID="ddlPreview" runat="server" Width="80%" Font-Size="12px">
<ItemStyle Wrap="False" />
<ItemTemplate>
<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 0px;">
<tr>
<td width="6%">
<asp:RadioButton ID="rbutn1" runat="server" GroupName="rb1" Text="A"/>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn2" runat="server" GroupName="rb1" Text="B"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn3" runat="server" GroupName="rb1" Text="C"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn4" runat="server" GroupName="rb1" Text="D"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn5" runat="server" GroupName="rb2" Text="A"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn6" runat="server" GroupName="rb2" Text="B"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn7" runat="server" GroupName="rb2" Text="C"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn8" runat="server" GroupName="rb2" Text="D"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn9" runat="server" GroupName="rb3" Text="A"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn10" runat="server" GroupName="rb3" Text="B"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn11" runat="server" GroupName="rb3" Text="C"//>
</td>
<td width="6%">
<asp:RadioButton ID="rbutn12" runat="server" GroupName="rb3" Text="D"//>
</td>
<td>
<asp:RadioButton ID="rbutn13" runat="server" GroupName="rb4" Text="A"//>
</td>
<td>
<asp:RadioButton ID="rbutn14" runat="server" GroupName="rb4" Text="B"//>
</td>
<td>
<asp:RadioButton ID="rbutn15" runat="server" GroupName="rb4" Text="C"//>
</td>
<td>
<asp:RadioButton ID="rbutn16" runat="server" GroupName="rb4" Text="D"//>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td><asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="提 交" /></td>
</tr>
</table>
{
string str = " ";
for (int i = 0; i < this.groupBox1.Controls.Count; i++)
{
RadioButton cb = this.groupBox1.Controls[i] as RadioButton;
if (cb.Checked == true)
{
str = cb.Text.ToString() + str;
}
}或foreach (RepeaterItem ri in Repeater1.Items)
{
foreach (Control ctl in ri.Controls)
{
RadioButton radTemp = ctl as RadioButton;
if (radTemp != null)
{
if (radTemp.Checked)
{
Response.Write(radTemp.Text);
}
}
}
}
MessageBox.Show(str);
}
{
for (int i = 0; i < this.Controls.Count; i++)
{
foreach (object item in Page.Controls[i].Controls)//遍历当前当前页面上的控件
{
if (item is RadioButton)
{
RadioButton lb = (System.Web.UI.WebControls.RadioButton )item;
Response.Write(lb.Text);//显示
}
}
}
}
上面的代码写在提交按钮敲击事件下,(跟批量给控件赋值差不多)