·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> Repeater内RadioButton.GroupName失效

Repeater内RadioButton.GroupName失效

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

Repeater内RadioButton.GroupName失效

最近在做项目时遇到要在repeater中显示多个radiobutton并且实现单选功能,于是很自然地就加上了GroupName,但事实是不行的,在repeater中的radiobutton呈现到页面的时候name会自动加上repeater的id、序列ct100和radiobutton的id,这就直接导致为什么GroupName会失效了。我在网上搜了有很多方法,但是都没适用的,比如用<input type=radio>、radiobuttonlist等,但是我既然用了radiobutton,就懒得换了,以下是我的代码实现:

页面

 1 <table> 2                             <tr> 3                                 <asp:Repeater runat="server" ID="repbgs"> 4                                     <ItemTemplate> 5                                         <td> 6                                             <asp:RadioButton runat="server"  ID="rdo1" Text='<%# Eval("name") %>' /> 7                                         </td> 8                                     </ItemTemplate> 9                                 </asp:Repeater>10                             </tr>11                         </table>

后台就一个绑定过程就不展示了,还有就是jQuery

1 $(':input:radio').click(function () {2                 if ($(this).is(':checked')) {3                     $(this).is(':checked');4 $(this).parents().siblings().children().removeAttr("checked");5                 }6             });

以上就是我的简单实现