Question

I have a nested datalist structure and want to put select all checkboxes on every cathegories.

the top checkbox works fine but dont know how to do it for per main cathegory

enter image description here

this works fine:

 protected void cbTamaminiSec_CheckedChanged(object sender, EventArgs e)
{
    CheckBox cbTemp;

    foreach (DataListItem ItemP in parentDataList.Items)
    {
        cbTemp = (CheckBox)parentDataList.Items[ItemP.ItemIndex].FindControl("cbTumunuSec");
        cbTemp.Checked = cbTamaminiSec.Checked;

        DataList nestedDataList = (DataList)parentDataList.Items[ItemP.ItemIndex].FindControl("nestedDataList");

        foreach (DataListItem Item in nestedDataList.Items)
        {
            cbTemp = (CheckBox)nestedDataList.Items[Item.ItemIndex].FindControl("cbTamam");

            cbTemp.Checked = cbTamaminiSec.Checked;
        }
    }
}

but don't know about partially select (below codes for the chechboxes in the parentdatalist) I put selected id as "0" to emphasize the problem

  protected void cbTumunuSec_CheckedChanged(Object sender, EventArgs e)
    {
        int selected = 0;//= (int)parentDataList.SelectedItem.ToString(); // problem is here..

        DataList nestedDataList = (DataList)parentDataList.Items[selected].FindControl("nestedDataList");

        foreach (DataListItem Item in nestedDataList.Items)
        {
            CheckBox cbTemp = (CheckBox)nestedDataList.Items[Item.ItemIndex].FindControl("cbTamam");

            cbTemp.Checked = true;

        }
    }

what is the solution

Was it helpful?

Solution 2

problem solved! asp code:

<asp:HiddenField ID="hiddenBaslikId" runat="server" Value='<%# Eval("baslikId") %>' />

code behind:

protected void cbTumunuSec_CheckedChanged(Object sender, EventArgs e)
    {
    CheckBox checkAll = (CheckBox)sender;
    DataListItem item = (DataListItem)checkAll.NamingContainer;
    HiddenField HiddenID = (HiddenField)item.FindControl("hiddenBaslikId");

    int selected = Convert.ToInt32(HiddenID.Value)-1;

        DataList nestedDataList = (DataList)parentDataList.Items[selected].FindControl("nestedDataList");

        foreach (DataListItem Item in nestedDataList.Items)
        {
            CheckBox cbTemp = (CheckBox)nestedDataList.Items[Item.ItemIndex].FindControl("cbTamam");

            cbTemp.Checked = true;

        }
    }

OTHER TIPS

You can try with this code - based on OfType LINQ Operator and Controls propery

var allControls = nestedDataList.Items[index].Controls.OfType<CheckBox>();

....//Filter with `Where Operator`

Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.control.controls(v=vs.80).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top