Wednesday, November 23, 2016

ASP.NET - One Radio Button Selected in Gridview

ASP.NET does not allow you to place a radio button in a gridview row and have only a single radio button selected at a time.

I came across this post that solved by problem.

http://www.dotnetlearners.com/blogs/view/216/allow-only-single-radio-button-selection-in-aspnet-gridview.aspx

It uses this javascript function to change the other selected value:

<script language="javascript">
    function singleRbtnSelect(chb) {
        $(chb).closest("table").find("input:radio").prop("checked", false);
        $(chb).prop("checked", true);
    }
</script>