asp.net - Checkbox in Repeater (Categories SubCategories Filtering) -
i tried 2 main category in repeater using checkbox , have no problem when try subcategories on same database table (using checkbox.checkchanged) first checkbox not responsing second working without problem. how can fix situation?
checbox filtering may not still needs fix.
list.aspx
<asp:repeater id="rptcat" runat="server"> <itemtemplate> <ul> <li> <asp:checkbox id="main_cat" runat="server" type="checkbox" oncheckedchanged="main_cat_checkchanged" autopostback="true" text='<%# eval("cat_name") %>' data-id='<%# eval("cat_id") %>' /> </li> </ul> </itemtemplate> </asp:repeater> <asp:repeater id="sub_cat" runat="server"> <itemtemplate> <ul> <li> <input runat="server" id="subcheck" type="checkbox" class="icheck" autopostback="true" text='<%# eval("cat_name") %>' /> </li> </ul> </itemtemplate> </asp:repeater>
list.aspx.cs
public void bring_cat() { dataset dscat = conn.bringit("select * categories sub_id=1"); rptcat.datasource = dscat.tables[0].defaultview; rptcat.databind(); subcheck.visible = false; } protected void main_cat_checkchanged(object sender, system.eventargs e) { foreach (repeateritem aitem in rptcat.items) { checkbox main_cat = (checkbox)aitem.findcontrol("main_cat"); var id = main_cat.attributes["data-id"]; if (main_cat.checked == true) { dataset ds_sub_cat = conn.bringit("select * categories sub_id="+id); sub_cat.datasource = ds_sub_cat.tables[0].defaultview; sub_cat.databind(); sub_cat.visible = true; subcheck.visible = true; } else { sub_cat.visible = false; subcheck.visible = false; } } }
when clicked on main checkbox getting id number , trying show subcheckbox relation.
could see wrong? have better idea it?
okay, solved problem. hope helps you.
if you're trying id number directly checkbox can see not working perfectly. solution simple. add hidden field control after checkbox in repeater or datalist , set value="<#eval("cat_id")" id number. now, can id number code behind without count problem.
i think there little bug, that's why we're using hiddenfield it. it's not best way can it's working.
Comments
Post a Comment