I tried to get two main category in repeater using checkbox and i have no problem with it but when i try to get subcategories on same database table (using Checkbox.CheckChanged) then first checkbox is not responsing but second is working without any problem. How can we fix this situation?
Checbox Filtering is may be not so good but it still needs to be 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 * from categories where 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 = baglan.DataSetGetir("Select * from categories where 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 i clicked on main checkbox then i am getting id number and trying to show subcheckbox with this relation.
Could you see what is wrong? Do you have better idea to do it?
Aucun commentaire:
Enregistrer un commentaire