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

[Solved] Can I expand an item after rebind?

2 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 11 Mar 2009, 10:18 PM
I have a nested view in my radgrid so that, when you expand an item you see the details of the item.  One of the things in there is a checkbox that changes a status.  I have it firing a standard checkbox event method (i.e. chkThisBox_CheckChanged(object sender, EventArgs e)...).  It updates the database.  I also have it rebinding the radgrid.  What I want to do is, after rebinding the radgrid, re-select and re-expand the item that was changed.  Here's what I have, which does not work:
    protected void chkApprehended_CheckChanged(object sender, EventArgs e)  
    {  
        var apprehended = ((CheckBox) sender).Checked;  
        var mwId = RadGrid1.SelectedValue.ToString();  
        var p = Person.GetWantedPerson(mwId);  
        p.Apprehended = apprehended;  
        p.ApprehendedDate = DateTime.Now;  
        Person.ApprehendPerson(p);  
        var thisRow = RadGrid1.SelectedItems[0];  
        RadGrid1.Rebind();  
        thisRow.FireCommandEvent("ExpandCollapse"new EventArgs());  
//        thisRow.Selected = true;  
//        thisRow.Expanded = true;  
    }  
 
I also have a RadGrid1_ItemCommand method that handles several commands, including the ExpandCollapse command.  But the line that has FireCommandEvent doesn't fire off the itemcommand method.  What am I missing here, and is this possible without client side code?

Thanks!

Eddie

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Mar 2009, 04:45 AM
Hi Eddie,

I guess the expanded/selected state of the hierarchical Grid is lost on Rebind. If so refer the following code library which explains how to retain the Expanded/Selected state of the Grid on rebind.
Retain expanded/selected state in hierarchy on rebind

Thanks
Shinu



0
Lee
Top achievements
Rank 2
answered on 04 Jun 2009, 01:38 AM
Hi, Eddie

Try this :

foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
               if (item.Expanded)
               {
                   item.Expanded = false;
                   item.FireCommandEvent(RadGrid.ExpandCollapseCommandName, new EventArgs());
                   item.Expanded = true;
               }
           }

hope it helps.

Eman Lee

Tags
Grid
Asked by
Software
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Lee
Top achievements
Rank 2
Share this question
or