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

RadGrid on Postback

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Atchut
Top achievements
Rank 1
Atchut asked on 08 May 2012, 07:50 PM
Hello,

I am using RadAJAX panel.

I have a radgrid and it has Expand and collapse functionality to expand and collapse rows.

If I expand rows and click on Update button, again it is showing in collapse mode. I want the Grid to appear like it looks before postback

What I have to do ?

TIA

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 May 2012, 06:31 AM
Hello Tia,

Referring to this code library, you can persist the collapsed state of groups on postback with the following code.
C#:
public Hashtable Groups
{
  get
  {
    if (ViewState["Groups"] == null)
    {
      Hashtable res = new Hashtable();
      ViewState["Groups"] = res;
      return res;
     }
     return (Hashtable)ViewState["Groups"];
   }
    set
     {
        ViewState["Groups"] = value;
      }
}
void RadGrid1_DataBound(object sender, EventArgs e)
{
  foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
  {
   if (Groups.ContainsKey(item.DataCell.Text))
   {
      item.Expanded = (bool)Groups[item.DataCell.Text];
   }
  }
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.ExpandCollapseCommandName)
  {
    Groups[((GridGroupHeaderItem)e.Item).DataCell.Text] = !e.Item.Expanded;
  }
}
protected void RadGrid1_GroupsChanging(object sender, GridGroupsChangingEventArgs e)
{
  Groups.Clear();
  foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
  {
    Groups[item.DataCell.Text] = item.Expanded;
  }
}
protected void Update_Click(object sender, EventArgs e)
{
  RadGrid1.Rebind();
}

Thanks,
Princy.
Tags
Grid
Asked by
Atchut
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or