locked
how to checked checkbox when div has class in repeater c#.net RRS feed

  • Question

  • User1439346456 posted

    hi guys

    we want checked checkbox when div has ".checked"

    <asp:Repeater ID="rpt" runat="server">
                       <ItemTemplate>
    <div class="icheckbox_flat-green checked" > <----this is checkbox cover and customized <tr class="even pointer"> <td class="a-center "> <input id="checkbox_chk" runat="server" type="checkbox" class="flat" name="table_records"> <asp:HiddenField ID="fieldID_hf" runat="server" Value='<%# Eval("fieldID")%>' /> </td> </tr>
      </div> </ItemTemplate> </asp:Repeater>

    thanks everyone.

    Monday, December 17, 2018 6:51 AM

All replies

  • User-2054057000 posted

    Try the following code:

    $(document).ready(function () {
      if($("#<%=rpt.ClientID%>").hasClass("checked")){
    $(this).find("input[type='checkbox']").prop('checked', true);
    } });

    For working with checkbox in jQuery see this tutorial.

    Monday, December 17, 2018 11:09 AM
  • User-1174608757 posted

    Hi shmail,

    According to your description ,I have made a sample here.I suggest you to use .icheckbox_flat-green.checked to get the div both has class 'icheckbox_flat-green' and class 'checked' then you can use : checkbox to find the checkbox in div. Here is the code.I hope it can help you.

    Test.aspx:

    <head runat="server">
        <title></title><script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(document).ready(function () {
              $(" .icheckbox_flat-green.checked :checkbox").prop("checked",true)
              
                
            })
        </script>
       </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                         <div  class="icheckbox_flat-green checked" > 
                               <tr class="even pointer">
                                   <td class="a-center ">                                                           
                                       <input id="checkbox_chk" runat="server" type="checkbox"  />
                                       <%# Eval("fruit") %>
                                   </td>                             
                               </tr>
                           </div>
                    </ItemTemplate>              
                </asp:Repeater>
    
                <asp:Repeater ID="Repeater2" runat="server">
           <ItemTemplate>
                         <div> 
                               <tr class="even pointer">
                                   <td class="a-center ">                                                           
                                       <input  runat="server" type="checkbox"  />
                                       <%# Eval("color") %>
                                   </td>                             
                               </tr>
                           </div>
                    </ItemTemplate>    
    
                </asp:Repeater>
            </div>
        </form>
    </body>

      Test.aspx.cs

     public partial class Test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string sql = "select * from db ";
                this.Repeater1.DataSource = SqlHelper.ExecuteDataTable(sql);
                this.Repeater1.DataBind();
                this.Repeater2.DataSource = SqlHelper.ExecuteDataTable(sql);
                this.Repeater2.DataBind();
    
            }
        }

    It shows:

    Best regards

    Wei Zhang

    Tuesday, December 18, 2018 5:39 AM