Validate at least one checkbox checked Validation for CheckBox inside Repeater in ASP.Net

Last Reply on Jan 29, 2014 02:36 AM By Mudassar

Posted on Jan 28, 2014 10:42 PM

I hv repeater control which contains checkbox. when user click on download button i want to check wheather user select atleast on checkbox using javascript not jquery.

Results 1 - 5 of 7 12
Posted on Jan 28, 2014 10:49 PM

i want to check wheather checkbox is selected by user or not. where checkbox is inside gridview


Posted on Jan 28, 2014 10:59 PM

What Data you are downloading.

where is your checkbox is it inside of GridView or Repeater

Thank you.

,

Posted on Jan 28, 2014 11:02 PM

i hv check box inside repeater so through javascript i just want to check wheather atleast one checkbox is selected by user or not.


Posted on Jan 28, 2014 11:10 PM

Try This

 

<asp:Repeater id="repeaterentry" runat="server">
    <HeaderTemplate>
        <table border="1" width="100%">
            <colgroup>
                <col style="width: 10px;" />
                <col />
                <col />
            </colgroup>
            <tr>
                <th align="left" class="allCheckbox">
                    <asp:CheckBox ID="allCheckbox1" runat="server" />
                </th>
                <th>
                    <asp:LinkButton ID="lnkbtn1" runat="server" CommandName="UserName">Name</asp:LinkButton>
                </th>
                <th>
                    Password
                </th>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td class="singleCheckbox">
                <asp:CheckBox ID="chkContainer" runat="server" />
            </td>
            <td>
                <%#Eval("uname") %>
            </td>
            <td>
                <%#Eval("upass")%>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
</asp:Repeater

in js

 

<script type="text/javascript">
    $(function () {
        var $allCheckbox = $('.allCheckbox :checkbox');
        var $checkboxes = $('.singleCheckbox :checkbox');
        $allCheckbox.change(function () {
            if ($allCheckbox.is(':checked')) {
                $checkboxes.attr('checked', 'checked');
            }
            else {
                $checkboxes.removeAttr('checked');
            }
        });
        $checkboxes.change(function() {
            if ($checkboxes.not(':checked').length) {
                $allCheckbox.removeAttr('checked');
            }
            else {
                $allCheckbox.attr('checked', 'checked');
            }
        });
    });
</script>

working example available


Posted on Jan 28, 2014 11:11 PM

Refer

http://forums.asp.net/t/1906476.aspx

http://dotnetmentors.com/aspnet/jquery-check-uncheck-all-checkboxes-in-gridview.aspx