在中继器中只选择一个单选按钮

Ali*_*hşi 3 asp.net repeater radio-button

我只想选择一个单选按钮,但我不能这样做.这是我的代码:

<asp:Repeater ID="Repeater_secenekler" runat="server" DataSource='<%#Eval("Secenekler")%>'>
   <HeaderTemplate>
       <table>
   </HeaderTemplate>
   <ItemTemplate>
       <tr>
           <td style="margin-left: 20px;">
               <asp:CheckBox ID="CheckBox" runat="server" Text='<%#Eval("OptionName")%>' Visible='<%# Eval("TypeId").ToString() == "1" %>' />
               <asp:RadioButton ID="RadioButton" runat="server" Text='<%#Eval("OptionName")%>' Visible='<%# Eval("TypeId").ToString() == "2" %>'
                    GroupName="RadioButtonGrup" />
           </td>
       </tr>
   </ItemTemplate>
   <FooterTemplate>
       </table>
   </FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

我可以选择具有相同组名的所有单选按钮,但我不想要这个.我只想要一个选择.

我怎样才能做到这一点.谢谢.

Cur*_*urt 14

这是使用RadioButtons的ASP.NET Repeater的一个众所周知的错误:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q316495

这里有一个修复:

http://www.ifinity.com.au/Blog/EntryId/87/Simple-fix-for-Radio-Button-controls-in-an-ASP-NET-Repeater-using-jQuery

jQuery("[name$='$optValue']").attr("name",jQuery("[name$='$optValue']").attr("name"));

jQuery("[name$='$optValue]").click(function (){ 
                //set name for all to name of clicked 
                jQuery("[name$='$optValue]").attr("name", this.attr("name")); 
            });
Run Code Online (Sandbox Code Playgroud)

  • 伟大的呼喊...有一个甜甜圈;-) (2认同)

小智 8

只需快速修复上述答案,即可在脚本执行时收到任何错误.

    $(function () {
    $('[name$="$YourGroupName"]').attr("name", $('[name$="$YourGroupName"]').attr("name"));

    $('[name$="$YourGroupName"]').click(function () {
        //set name for all to name of clicked 
        $('[name$="$YourGroupName"]').attr("name", $(this).attr("name"));
    });
});
Run Code Online (Sandbox Code Playgroud)