psiegers45
Top achievements
Rank 1
psiegers45
asked on 08 Jan 2010, 04:42 PM
Hi, I haven't been able to find out why my RadGrid (used in hierarchical mode with one master/detailtable and commanditems on top (add new record)) does not maintain viewstate after adding a new record, either in mastertableview or in the detailtable. All expanded items close after rebinding occurs and I haven't been able to find out why yet.
I have seen this working in the demo page at http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
I'm using Telerik Radcontrols for ASP.NET AJAX Q3 2008.
Thanks in advance for any help on this topic.
Regards, Pieter
I have seen this working in the demo page at http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
I'm using Telerik Radcontrols for ASP.NET AJAX Q3 2008.
Thanks in advance for any help on this topic.
Regards, Pieter
4 Answers, 1 is accepted
0
Accepted
Schlurk
Top achievements
Rank 2
answered on 08 Jan 2010, 05:05 PM
I think that if you follow the example given in this forum post from a Telerik team member you will be able to get a solution. You should just need a bit of coding for saving / loading the expanded items :)
0
psiegers45
Top achievements
Rank 1
answered on 08 Jan 2010, 09:28 PM
Thanks for the pointer Schlurk, one question, do I need to enable the grouping stuff to make it work, or can I just iterate through the items in master/detail and save expanded state in session vars?
Regards, Pieter
Regards, Pieter
0
Schlurk
Top achievements
Rank 2
answered on 08 Jan 2010, 10:18 PM
You should be able to just iterate through all of the items and save the expanded state in session. The example I provided was a little bit more complex so it has a bit of logic you do not need!
0
psiegers45
Top achievements
Rank 1
answered on 11 Jan 2010, 06:16 PM
Very well, below is the code I have implemented today, looks like it is working so I wanted to share it with the community; if any improvements are needed along the way I'll post them too; also pls let me know if anyone finds issues with this approach.
| void rgDiasGastos_DataBinding(object sender, EventArgs e) |
| { |
| SaveGroupsExpandedState(rgDiasGastos); |
| } |
| void rgDiasGastos_DataBound(object sender, EventArgs e) |
| { |
| LoadGroupsExpandedState(rgDiasGastos); |
| } |
| private void SaveGroupsExpandedState(RadGrid grid) |
| { |
| List<int> collapsedIndexesDias = new List<int>(); |
| List<int> collapsedIndexesGastos = new List<int>(); |
| foreach (GridDataItem itemDia in rgDiasGastos.MasterTableView.Items) |
| { |
| if (itemDia.Expanded) |
| { |
| collapsedIndexesDias.Add(itemDia.RowIndex); |
| } |
| foreach (GridDataItem itemGasto in itemDia.ChildItem.NestedTableViews[0].Items) |
| { |
| if (itemGasto.Expanded) |
| { |
| collapsedIndexesGastos.Add(itemGasto.RowIndex); |
| } |
| } |
| } |
| Session["groupExpandedStateDias"] = collapsedIndexesDias; |
| Session["groupExpandedStateGastos"] = collapsedIndexesGastos; |
| } |
| private void LoadGroupsExpandedState(RadGrid grid) |
| { |
| List<int> collapsedIndexesDias = Session["groupExpandedStateDias"] as List<int>; |
| List<int> collapsedIndexesGastos = Session["groupExpandedStateGastos"] as List<int>; |
| if (collapsedIndexesDias != null) |
| { |
| foreach (GridDataItem itemDia in rgDiasGastos.MasterTableView.Items) |
| { |
| if (collapsedIndexesDias.Contains(itemDia.RowIndex)) |
| { |
| itemDia.Expanded = true; |
| } |
| if (collapsedIndexesGastos != null) |
| { |
| foreach (GridDataItem itemGasto in itemDia.ChildItem.NestedTableViews[0].Items) |
| { |
| if (collapsedIndexesGastos.Contains(itemGasto.RowIndex)) |
| { |
| itemGasto.Expanded = true; |
| } |
| } |
| } |
| } |
| } |
| } |
Regards, Pieter