How to programmatically expand group row?

2 replies. Last post: September 16, 2010 8:14 AM by Mladen Maras
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Mladen MarasMember

I have an aspx page with button and grid. When button is clicked, modal dialog is shown for adding new item. After closing modal dialog, grid sends custom postback like this:

function NewItem() {
            var result = showModalDialogIframe("Edit.aspx", "", "dialogWidth=1000px;dialogHeight=800px");
            if (result == '1') {
                var grid = ISGetObject("WebGrid1");
                grid.SendCustomRequest();
            }
        }

On the server side in the WebGrid1_InitializePostBack event handler datasource is refreshed like this:

protected void WebGrid1_InitializePostBack(object sender, PostbackEventArgs e)
        {
            if (e.Action == ISNet.WebUI.WebGrid.PostBackAction.Custom)
            {
                // refresh webgrid data
                DoInitializeDataSource();
                WebGrid1.DataSource = ds;
                WebGrid1.ClientAction.Refresh();
            }
        }

Grid has 3 levels of grouping. I want to show new item and coresponding groups expanded.

I did something like this:

protected void WebGrid1_InitializeRow(object sender, RowEventArgs e)
        {
            if (e.Row.Type == ISNet.WebUI.WebGrid.RowType.Record)
            {
                if (e.Row.Table.IsRootTable)
                {
                    int newID = Convert.ToInt(Session["NewID"]);
                    if (e.Row.KeyValue.ToString() == newID.ToString())
                    {
                        var rootRow = e.Row.GetRootRow();
                        bool found = false;
                        foreach (WebGridRow rr in rootRow.Children)
                        {
                            foreach (WebGridRow rr2 in rr.Children)
                            {
                                if (rr2.Cells[0].Text == e.Row.Parent.Cells[0].Text)
                                {
                                    rootRow.ExpandGroupRow();
                                    rr.ExpandGroupRow();
                                    rr2.ExpandGroupRow();
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                        }
                        //e.Row.Expanded = true;
                        Session["NewID"] = null;
                    }
                }
            }
            
        }

However, it doesn't work, at least not completely. The way it works is shown in the attached screenshot.

Is there an easier or better way to expand all the groups all the way down to the one row?

1 attachment
All times are GMT -5. The time now is 4:38 PM.
Previous Next