只有在转发一个单选按钮选择(only one radiobutton selection in re

2019-06-25 12:48发布

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

<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>

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

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

Answer 1:

这是一个众所周知的错误使用单选按钮的ASP.NET直放站:

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")); 
            });


Answer 2:

就在上述回答的快速修复,所以你不会在执行脚本时得到任何错误。

    $(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"));
    });
});


文章来源: only one radiobutton selection in repeater