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

Radgrid collapse not working.

11 Answers 413 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 19 Oct 2010, 04:21 AM
Hi!
Due to some requirements the datasource in the nestedviewtemplate are supplied programmatic in the ItemCommand,
everything works fine when expanding and the data are loaded but when I click collapse the selected row won't collapse and instead it just post back and displays the same-thing.
Is there a way to programmatically collapse the nestedview of a selected row when collapse is clicked?
Also I'm not allowed to use sqldatasource because the data is from List<T>.

Thanks!

11 Answers, 1 is accepted

Sort by
0
Neil
Top achievements
Rank 1
answered on 19 Oct 2010, 06:13 AM
Also, collapse is not working when HierarchyLoadMode="ServerOnDemand";
0
Pavlina
Telerik team
answered on 19 Oct 2010, 09:27 AM
Hi Neil,

Try using Advanced DataBinding for the grid in NestedViewTemplate. Attach OnNeedDataSource event to grid and write the code for populating grid in the event handler, instead of trying in ItemCommand event. Please checkout the demo which demonstrates how to use Advanced DataBinding.
Advanced Data Binding

Kind regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Neil
Top achievements
Rank 1
answered on 19 Oct 2010, 09:44 AM
Hi Pavlina,

I've already done that but it has a problem, the data in the nested view wont show up unless I bind the radgrid.
And as we all know we cannot call Bind after the OnNeedDataSource.
(Please Note that inside the nested view are asp:details view that are binded to the source)

Thanks!
0
Pavlina
Telerik team
answered on 20 Oct 2010, 10:01 AM
Hi Neil,

If the issue persists, it will be best if you send us a small runnable project which demonstrates the issue. Thus we will be able to we debug the project and provide you with more to-the-point answer.

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
rosborn
Top achievements
Rank 1
answered on 01 Nov 2010, 04:54 PM
I'm also interested in the solution, as I'm having the same problem.
0
Pavlina
Telerik team
answered on 03 Nov 2010, 12:51 PM
Hello Roger,

Can you make sure that EnableViewState property of the grid is set to true? Please take into account that some operations in Telerik RadGrid like data extraction through the ExtractValuesFromItem method, grouping, hierarchical views expand/collapse, custom edit forms or filtering require that view state is enabled.

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Niraj
Top achievements
Rank 1
answered on 07 Jan 2011, 10:42 AM
.
0
aaron
Top achievements
Rank 1
answered on 05 Nov 2011, 12:31 PM
 private void CollapseAll()
    {
        foreach (GridItem item in radGridDocument.MasterTableView.Controls[0].Controls)
        {
            if (item is GridGroupHeaderItem)
            {
                item.Expanded = false;
            }
        }
    }
    private void ExpandAll()
    {
        foreach (GridItem item in radGridDocument.MasterTableView.Controls[0].Controls)
        {
            if (item is GridGroupHeaderItem)
            {
                item.Expanded = true;
            }
        }
    }


This is the code i am using on click event,but even though grid is not getting collapse.
0
Pavlina
Telerik team
answered on 09 Nov 2011, 12:52 PM
Hello Aaron ,

Please follow the approach from the code library below in order to implement the desired functionality and see if it works as expected.
Custom expand/collapse column with ExpandAll/CollapseAll image button in the header

I hope this helps.

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Baiju
Top achievements
Rank 1
answered on 01 Mar 2016, 01:45 PM

I also have the same issue and resolved it.

For resolving the issue , i used two hidden fields

     <asp:HiddenField ID="hdnExpandCollapse" Value="0" runat="server" />

     <asp:HiddenField ID="hdnExpanded" Value="0" runat="server" />

Then the following two grid events are used to capture the state of the grid item

         /* Start functions used for collapse the grid  */
        protected void Grid_PreRender(object sender, EventArgs e)
        {
            int i = 0;
            foreach (GridDataItem item in Grid.MasterTableView.Items)
            {
                 GridTableView DetailsTable = (GridTableView)item.OwnerTableView;
             
                 System.Collections.Hashtable ht = DetailsTable.DataKeyValues[i];


                string strDataKey= ht["DataKey"].ToString();
                if (strDataKey == hdnExpandCollapse.Value)
                     {
                         if (hdnExpanded.Value == Territory)
                         {
                             item.Expanded = false;
                             hdnExpanded.Value = "0";
                         }
                         else
                         {
                             item.Expanded = true;

                             hdnExpanded.Value = Territory;
                         }

                     }
                     
                     i++;
            }
        }


        protected void Grid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                hdnExpandCollapse.Value = ((EntityClass)(e.Item.DataItem)).DataKey.ToString();

            }
        }
        /* End functions used for collapse the grid  */

0
Pavlina
Telerik team
answered on 01 Mar 2016, 03:05 PM
Hello Baiju,

Thank you for sharing your solution with the community.

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Neil
Top achievements
Rank 1
Answers by
Neil
Top achievements
Rank 1
Pavlina
Telerik team
rosborn
Top achievements
Rank 1
Niraj
Top achievements
Rank 1
aaron
Top achievements
Rank 1
Baiju
Top achievements
Rank 1
Share this question
or