How to restrict the user to allow only one checkbox of each checked? (ASP.NET)


<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”chkbox_checked_uncheked.aspx.cs”
    Inherits=”Ediable_Repeater.chkbox_checked_uncheked” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
    <title></title>
    <script src=”Scripts/jquery-1.6.2.min.js” type=”text/javascript”></script>

    <script type=”text/javascript”>

        $(document).ready(function () {
            $(‘#C1All’).click(function () {
                $(‘.col1 > input’).attr(“checked”, $(‘#C1All’).attr(“checked”));
                $(‘.col2 > input’).removeAttr(“checked”);
                $(‘#C2All’).removeAttr(“checked”);
            });

            $(‘#C2All’).click(function () {
                $(‘.col2 > input’).attr(“checked”, $(‘#C2All’).attr(“checked”));
                $(‘.col1 > input’).removeAttr(“checked”);
                $(‘#C1All’).removeAttr(“checked”);
            });

            $(‘.col1’).each(function () {
                $(this).click(function () {
                    var id = $(“input”, this).attr(‘id’);
                    var coresId = id.replace(‘C1’, ‘C2’);
                    $(‘#’ + coresId).removeAttr(“checked”);
                    $(‘#C1All’).removeAttr(“checked”);
                    $(‘#C2All’).removeAttr(“checked”);
                });
            });

            $(‘.col2’).each(function () {
                $(this).click(function () {
                    var id = $(“input”, this).attr(‘id’);
                    var coresId = id.replace(‘C2’, ‘C1’);
                    $(‘#’ + coresId).removeAttr(“checked”);
                    $(‘#C1All’).removeAttr(“checked”);
                    $(‘#C2All’).removeAttr(“checked”);
                });
            });
        });

  </script>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        <div>
            <table border=”1″>
                <tr>
                    <td>
                        <asp:CheckBox ID=”C1All” runat=”server”   Text=”approve all” />
                    </td>
                    <td>
                        <asp:CheckBox ID=”C2All” runat=”server”   Text=”Reject all” />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID=”C101″ runat=”server” Text=”john 0″ />
                    </td>
                    <td>
                        <asp:CheckBox ID=”C201″ runat=”server”  Text=”john 0″ />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID=”C102″ runat=”server” Text=”john 1″ />
                    </td>
                    <td>
                        <asp:CheckBox ID=”C202″ runat=”server”  Text=”john all” />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID=”C103″ runat=”server” Text=”john 2″ />
                    </td>
                    <td>
                        <asp:CheckBox ID=”C203″ runat=”server”  Text=”John 2″ />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </form>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

*