only one radiobutton selection in repeater

前端 未结 2 1015
旧巷少年郎
旧巷少年郎 2020-12-18 09:24

I want to select only one radio button but I cant do this. Here is my code:



        
相关标签:
2条回答
  • 2020-12-18 09:39

    This is a well known bug with the ASP.NET Repeater using RadioButtons:

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

    There is a fix available here:

    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")); 
                });
    
    0 讨论(0)
  • 2020-12-18 09:41

    Just a quick fix of the above answer so you don't get any errors when the script is executed.

        $(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"));
        });
    });
    
    0 讨论(0)
提交回复
热议问题