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

[Solved] Dynamic expand item server-side

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 24 Sep 2009, 12:55 PM
Hi,

I have a RadGrid with a detailtable.
Given a certain condition i would like to expand an item dynamically usiong the following code
protected void customerRadGrid_ItemDataBound(object sender, GridItemEventArgs e)  
{             
  if (e.Item is GridDataItem)  
  {  
    if (MyExpandCondition((e.Item as GridDataItem)))  
    {  
      item.Expanded = true;  
    }  
  }               

Just setting the Expanded property to true doesn't seem to work. I debugged it and CanExpand is still false (because the ChildItem is still null) at this time.
The HierarchyLoadMode is set to the default one (ServerOnDemand)

I found out that when the user clicks the expand button a firecommand method is called with "ExpandCollapse" and the

ItemIndexHierarchical

 as parameters.
So i changed the "item.Expanded = true" line into "item.FireCommandEvent(RadGrid.ExpandCollapseCommandName, item.ItemIndexHierarchical)" but that doesn't seem to do what i expected.

Does anybody know how to expand this server-side? Or is there a Telerik demo that shows how to do this?

Thanks in advance!

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Sep 2009, 02:17 PM
Hello Marco,

You can try expanding the row based on your condition in the PreRender event of the grid:
c#:
 protected void customerRadGrid_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem dataItem in customerRadGrid.MasterTableView.Items) 
        {         
             if (condition is satisfied) 
                { 
                    dataItem.Expanded = true
                } 
        }        
    } 

Regards
Princy.
Tags
Grid
Asked by
Marco
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or