Nirmala
Nirmala

Reputation: 91

validate repeator with checkbox using jquery(check atleast one checkbox)

In asp.net I am using repeator having checkbox as childnode which is dynamically filled by database. I need to check atleast one checkbox using jquery and display message.how to pls anybody help me.

My repeator code

  <asp:Repeater ID="id_repSearch" runat="server">
     <HeaderTemplate>
        <table style="border: 1px solid #465c71;" cellpadding="5" width="100%">
           <tr style="background-color: #465c71; color: White" align="center">
               <td width="20%" align="center">Firstname</td>
               <td width="20%" align="center">Lastname</td>
               <td width="40%" align="center">Emailid</td>
               <td width="35%" align="center">Mobileno</td>
           </tr>
         </table>
      </HeaderTemplate>
      <ItemTemplate>
         <table width="100%">
           <tr style="background-color: FFECD8">
               <td><asp:CheckBox ID="id_chkSearch" runat="server" /></td>
               <td width="20%" align="left">
                  <%# DataBinder.Eval(Container.DataItem, "c_first_name") %></td>
               <td width="20%" align="left">
                  <%# DataBinder.Eval(Container.DataItem, "c_last_name") %></td>
               <td width="40%" align="left">
                  <%# DataBinder.Eval(Container.DataItem, "c_email_id") %></td>
               <td width="20%" align="left">
                  <%# DataBinder.Eval(Container.DataItem, "c_mobile_phone") %></td>
           </tr>
           <asp:HiddenField ID="hiddenuserid" runat="server" Value='<%#Eval("n_user_id") %>' />
           <asp:HiddenField ID="hiddenemail" runat="server" Value='<%#Eval("c_email_id") %>' />
           <asp:HiddenField ID="hiddenname" runat="server" Value='<%#Eval("c_first_name") %>' />
       </ItemTemplate>
       <SeparatorTemplate>
            <tr>
               <td>
                   <hr />
               </td>
            </tr>
        </SeparatorTemplate>
  </asp:Repeater>

Upvotes: 0

Views: 1471

Answers (1)

J0HN
J0HN

Reputation: 26961

Simpliest way would be to place a CssClass attrtibute with some unique value into all those checkboxes, and than use a jQuery selector to check if any is selected

.....
<ItemTemplate>
    <tr style="background-color: FFECD8">
    <td>
        <asp:CheckBox ID="id_chkSearch" runat="server" CssClass="i_am_unique_class_name"/>
    </td>
 .....

And jQuery:

$('.i_am_unique_class_name:checked').length //gives you the number of selected checkboxes with attached class

See CssClass, .length and :checked manual pages for details.

Upvotes: 1

Related Questions