This is a migrated thread and some comments may be shown as answers.

Radgrid expand several details programmatically

1 Answer 526 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vladimír
Top achievements
Rank 1
Vladimír asked on 11 Aug 2014, 11:57 AM
Hi,
till now I tried to search forums for about 3 hrs, no effort.

I have a RadGrid w MasterTable and DetailTable in it.
The Master contains list of groups, Detail can show members of groups.
Both table data are persisted in viewstate, having added column to store selection of records.

I've added a checkbox for selecting the whole group to the MasterTable. The detail table also contains an added checkbox to select any of the members individually. On checkedChanged the values in underlying data tables are set accordingly (when group is selected, all members are selected too, when any member is unselected, the group is set to loose selection thus not all member are selected any more) - that works fine.

What i am trying to do is:
If there exists at least 1 selected member in the group, I want the detail to remain expanded, but cannot find any way to do this.

My last try was to place a foreach loop in pageload_Complete to iterate through the underlying data searching for checked (selected) members.
When such a member is found, I tell the RadGrid to .Expanded = true for the according group, but it does not happen.

Even when I step through the methods and check the state of .Expanded after setting it to true, it still remains false. Why?

1 Answer, 1 is accepted

Sort by
0
Vladimír
Top achievements
Rank 1
answered on 12 Aug 2014, 08:40 AM
Finally got it..

in Page_LoadComplete i call a method ExpandWhereSelectedMembers() to handle that:

        protected void ExpandWhereSelectedMembers()
        {
            foreach (GridDataItem gr in grdGroups.MasterTableView.Items)
            {

                Label lblIdGroup = (Label)gr.FindControl("lblId");

                if (lblIdGroup != null)
                {
                    // checking for isChecked in underlying tabMembers for current groupId
                    var isChecked = from DataRow x in tabMembers.Rows where x.Field<bool>("isChecked") == true && x.Field<long>("groupId") == int.Parse(lblIdGroup.Text) select true;

                    if (isChecked.Count() > 0)
                    // expand group item in masterTable
                    {
                        gr.Expanded = true;
                    }
                }
            }
        }
Tags
Grid
Asked by
Vladimír
Top achievements
Rank 1
Answers by
Vladimír
Top achievements
Rank 1
Share this question
or