我有一个中继器和中继器内的单选按钮控制,在后面的代码我填的单选按钮控制的组名,所以,当我运行它,我有一个表有许多行,其中一些有单选按钮:组名不超过一个单选按钮转发asp.net里面工作
<asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" ViewStateMode="Enabled">
<HeaderTemplate>
<table class="table table-responsive table-bordered ">
<tr class="text-center" style="background-color: #6e6259; color: white;">
<th class="text-center">DESCRIPTION</th>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="padding-left: 20px;">
<asp:RadioButton ID="rbtDinamic" OnCheckedChanged="rbtDinamic_CheckedChanged" AutoPostBack="true"
ViewStateMode="Enabled" Visible="false" GroupName='<%#Eval("groupvalue") %>' runat="server"/></td>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
而在直放站的ItemDataBound我填的是价值组名:
Private Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Try
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
If CType(e.Item.FindControl("hdf1"), Label).Text = False Then
CType(e.Item.FindControl("rbtDinamic"), RadioButton).Visible = True
CType(e.Item.FindControl("rbtDinamic"), RadioButton).GroupName = CType(e.Item.FindControl("groupvalue"), Label).Text = False
End If
End If
Catch ex As Exception
End Try
End Sub
但是当我运行它的中继器创建组名称与不同的名称:
Radiobutton row 1:
Repeater1$ctl05$1
Radiobutton row 2:
Repeater1$ctl06$1
所以这让检查所有的单选按钮,当另一个用于同一组cheked而不是取消。
我发现在一个论坛上的代码,但只有当我只有一个组名它的工作,但我可以有一个以上的组名:
Protected Sub rbtDinamic_CheckedChanged(sender As Object, e As EventArgs)
For Each item As RepeaterItem In Repeater1.Items
Dim rbtn As RadioButton = DirectCast(item.FindControl("rbtDinamic"), RadioButton)
rbtn.Checked = False
Next
DirectCast(sender, RadioButton).Checked = True
End Sub
但有一点是单选按钮的多个组,所以在这种情况下我不能使用这个代码。
在哪里有做到这一点?谢谢
感谢您的回答,我有一个问题,对于idx和榆树有什么价值? –
它们分别包含array_中元素的_index和_element_本身。 jQuery将为你提供它们;不需要你做任何事情来初始化它们。只需在函数体内使用它们,传递给'.each'方法。 –