asp.net radio button grouping

后端 未结 10 430
余生分开走
余生分开走 2020-12-05 09:47

I am currently having an issue with radio buttons and grouping. I have an asp radio button within a repeater control. I have the group name attribute set to \"Customer\". Wh

相关标签:
10条回答
  • 2020-12-05 10:19

    I made my radiobutton have autopostback set to true, and then in the event handler set all the other radio buttons to BE unselected.

    Not ideal, but I need lots control over the visibility and enabled attributes of the radiobutton, and it seemed easier to let ASP.NET control that rather than resorting to client side script.

    0 讨论(0)
  • 2020-12-05 10:20

    I fixed it in javascript:

    $(function () {
      $("#divWithGridViewOrRepeater input:radio").attr("name", "yourGroupName");
    }); 
    
    0 讨论(0)
  • 2020-12-05 10:20

    I did this:

    $("input:radio").attr("name", $("input:radio").first().attr("name"));
    

    Why? because if you replace the name property for any string you want, you will get an 'not found error'. So, you need to get the name of the first radiobutton, and rename all of them with that name. It works like a sharm ;)

    0 讨论(0)
  • 2020-12-05 10:22

    My solution, similar to others:

    <input id="ctlRadio" runat="server" type="radio" data-fixgroupbug="1" >
    
    // Fixes this ASP.NET bug: if radio input is inside repeater you can't set its name.
    // Every input gets set different name by ASP.NET.
    // They don't behave as a group. You can select multiple radios.
    function fixRadiogroupBug()
    {
        $('[type="radio"][data-fixgroupbug]').click(function () {
            $(this).siblings('[type="radio"]').prop('checked', false);
        });
    }
    
    $(document).ready(function () {
        fixRadiogroupBug();
    });
    
    0 讨论(0)
  • 2020-12-05 10:28

    I would start by adding a value on my radiobutton Value='<%#Eval("CustomerNumber") %>'.

    0 讨论(0)
  • 2020-12-05 10:29

    This is a well known bug with the ASP.NET Repeater using RadioButtons: here best solution in my opinion

    0 讨论(0)
提交回复
热议问题