javascript - Handling checkboxlist inside Repeater control using asp.net -


after binding repeater contron, check box looks below,

i have 2 doubts here..

1 - if select checkbox of group 1, items under group 1 should selected. how can ?

2 - , have "select all" button when clicked should select items of groups. since checkbox inside repeater control, not sure how handle it. please help

  group 1        item 1        item 2      group 2        item 3        item 4      group 3        item 5         item 6       aspx :       <ol>         <asp:repeater id="rp_groups" runat="server" onitemdatabound="rp_groups_itemdatabound">             <itemtemplate>                 <ul>                     <asp:checkbox repeatcolumns="2" runat="server" id="chk_group" text='<%# eval("category_type") %>' value='<%# eval("service_type_category_id") %>' onclick="ongroupclick" />                       <asp:checkboxlist runat="server" id="chkservicetype" style="padding-left:20px" datavaluefield="servicetypeid" datatextfield="name" enableviewstate="true"                      ></asp:checkboxlist>                    <br />                 </ul>             </itemtemplate>         </asp:repeater>     </ol>  <script type="text/javascript">     function ongroupclick(group) {    for(item in group.getelementsbytagname('input')) {      item.checked = group.checked;   } }     function selectall() {         $("#<%=chkservicetype.clientid %> input[type=checkbox]").each(function () {             this.checked = true;         })     } </script> 

you need add checkbox onclick event repeater itemdatabound event follow call javascript function.

protected void rp_groups_itemdatabound(object sender, repeateritemeventargs e)     {          try         {             system.web.ui.webcontrols.checkbox chk =  (system.web.ui.webcontrols.checkbox)e.item.findcontrol("chk_group");              chk.attributes.add("onclick", "selectgroupall("+chk.clientid+");");         }          catch (exception ex)          {           }      } 

then need write function in javascript

1) function select group checkbox (i passing client id of checkbox group page behind. finding check box belong 1 group , make them checked true.)

function selectgroupall(chk) {                        $(chk).parent().parent().find(":checkbox").attr("checked", true);          } 

2) select on button click

write function in javascript , call button click event

function selectall() {              $(':checkbox').each(function () {                 this.checked = true;             });         } 

button form calling function

 <input type="button" value="test" onclick="selectall();" /> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -