[英]Access all RadioButton from a Repeater
I have a Repeater
of RadioButton
. 我有一个
RadioButton
的Repeater
。 Is there an easy way to access all these RadioButton
from the C# side? 有没有一种简单的方法可以从C#端访问所有这些
RadioButton
? For example, maybe access by the GroupName
? 例如,也许通过
GroupName
访问? I couldn't find anything simple online. 我在网上找不到任何简单的东西。
ASPX: ASPX:
<asp:Repeater ID="rptOtherNetworks" runat="server" >
<HeaderTemplate>
<li data-theme="c" data-role="list-divider" class="ui-li ui-li-divider ui-bar-b">
<asp:Localize ID="locRecentlySelected" runat="server"
EnableViewState="False" meta:resourcekey="locRecentlySelectedResource1"
Text="Select Network from Other Cameras">
</asp:Localize>
</li>
</HeaderTemplate>
<ItemTemplate>
<li data-theme="c">
<!-- I want to access these -->
<asp:RadioButton Text='<%# Eval("NetworkDescription") %>' data-mac='<%# Eval("MAC") %>'
Checked="False" GroupName="RadioGroupNetworkCameras" runat="server" />
</li>
</ItemTemplate>
</asp:Repeater>
Well, you can retrieve all of the RadioButtons by finding them by their ID in each of the RepeaterItems. 好了,您可以通过在每个RepeaterItems中按其ID查找它们来检索所有RadioButton。
<asp:RadioButton ID="rb"
Text='<%# Eval("NetworkDescription") %>'
data-mac='<%# Eval("MAC") %>'
Checked="False"
GroupName="RadioGroupNetworkCameras"
runat="server" />
foreach (RepeaterItem ri in rptOtherNetworks.Items)
{
if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
{
RadioButton r = (RadioButton)ri.FindControl("rb");
}
}
But a problem you are going to run into is that within the Repeater, the radio buttons will not be mutually exclusive . 但是您要遇到的问题是,在Repeater中,单选按钮不会相互排斥 。 There are various ways of "fixing" this through JavaScript and other methods, but just be aware this.
有多种通过JavaScript和其他方法“修复”此问题的方法,但请注意这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.