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

Expand collapse problem

3 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ajay
Top achievements
Rank 1
ajay asked on 25 Sep 2008, 12:06 PM

Respected sir,

 

Thank you for giving me solution to expand collapse functionality. Of rad grid

 

 protected void RadGrid1_PreRender(object sender, EventArgs e) 

    { 

        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 

        { 

            if (item.Expanded) 

            {  

foreach (GridTableView childTableView in item.ChildItem.NestedTableViews)

                {

                  

                    foreach (GridDataItem childitem in childTableView.Items)

                    {

                        childitem.Expanded = true;

                                        }

                              }

            } 

        } 

    } 

 

 

 

, now I want to call this function on update event of parent. I.e. if I click on update button its child items should expand.

Following is the code I have written for same,

 

protected void gvClientSetup_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

    {

        if (e.CommandName != "ExpandCollapse")

        {

            if (e.Item.OwnerTableView.Name == "gvClientSetup")

            {

 

                if (e.CommandName == "PerformInsert" || e.CommandName == "Update")

                {

                    gvClientSetup_Insert_Update(source, e);

                    gvClientSetup_PreRender(source, e);  

                               }

                                bindGrid()

                      }

               }

}             

 

It jump to pre render procedure , but  if (item.Expanded)  returns false

How should I make this to return true so that it will expand child items

 

Thanks.

Ajay

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Sep 2008, 12:27 PM
Hi Ajay,

One suggestion will be to expand the item in the ItemCommand event and then expand the child item in the PreRender event.

CS:
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "UpdateItem") 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            item.Expanded = true
             
        } 
    } 


 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item.Expanded) 
            { 
                GridTableView childTableView = item.ChildItem.NestedTableViews[0]; 
 
                foreach (GridDataItem childitem in childTableView.Items) 
                { 
                    childitem.Expanded = true
                } 
            } 
        } 
    } 


Thanks
Shinu.
0
ajay
Top achievements
Rank 1
answered on 26 Sep 2008, 12:18 PM

hi shinu


I have tried that code but it gives Exception on casting 

 GridDataItem item =  (GridDataItem )e.Item; 

 

0
ajay
Top achievements
Rank 1
answered on 26 Sep 2008, 12:23 PM
Unable to cast object of type 'Telerik.Web.UI.GridEditFormItem' to type 'Telerik.Web.UI.GridDataItem'.

This is the exception
Tags
Grid
Asked by
ajay
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ajay
Top achievements
Rank 1
Share this question
or