﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to programmatically expand group row?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-programmatically-expand-group-row/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to programmatically expand group row?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-programmatically-expand-group-row/</link><pubDate>Thu, 16 Sep 2010 08:14:51 GMT</pubDate><dc:creator>Mladen.maras@combis.hr</dc:creator><description>&lt;p&gt;For my case, that can't work. On my button click function row is inserted in the database. That is why I use grid.SendCustomRequest(); and  WebGrid1_InitializePostBack event handler so that datasource is refreshed with new row.&lt;/p&gt;
&lt;p&gt;Also, your approach to expanding is top to bottom. Your code gets first group and expands it, and then expands all the children. I want to expand only groups and subgroups that lead to the new row (the one that was inserted on button click). &lt;/p&gt;
&lt;p&gt;However, I found another way.&lt;/p&gt;
&lt;p&gt;On the server-side in InitializeRow event handler, I first detect positions of the coresponding groups and invoke function on the client-side with those group positions.&lt;/p&gt;&lt;pre&gt;protected void WebGrid1_InitializeRow(object sender, RowEventArgs e)
        {
            if (e.Row.Type == ISNet.WebUI.WebGrid.RowType.Record)
            {
                if (e.Row.Table.IsRootTable)
                {
                    int? newSastanakID = ConvertSafeNullable.ToInt(Session["NoviSastanak"]);
                    if (newSastanakID.HasValue &amp;amp;&amp;amp; e.Row.KeyValue.ToString() == newSastanakID.Value.ToString())
                    {
                        var rootRow = e.Row.GetRootRow();
                        bool found = false;
                        int rootLevel = 0;
                        int subLevel = 0;
                        int subsublevel = 0;
                        foreach (WebGridRow rr in rootRow.Children)
                        {
                            foreach (WebGridRow rr2 in rr.Children)
                            {
                                if (rr2.Cells[0].Text == e.Row.Parent.Cells[0].Text)
                                {
                                    rootLevel = rootRow.Position;
                                    subLevel = rr.Position;
                                    subsublevel = rr2.Position;
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                        }
                        WebGrid1.ClientAction.InvokeScript("ExpandToRow", new ISNet.WebUI.FunctionParameter[] { new ISNet.WebUI.FunctionParameter(rootLevel.ToString(), "int"), new ISNet.WebUI.FunctionParameter(subLevel.ToString(), "int"), new ISNet.WebUI.FunctionParameter(subsublevel.ToString(), "int") });
                        Session["NoviSastanak"] = null;
                    }
                }
                
            }
}&lt;/pre&gt;
&lt;p&gt;The client-side function looks like this:&lt;/p&gt;&lt;pre&gt; function ExpandToRow(rootLevel, subLevel, subsubLevel) {
            var grid = ISGetObject("WebGrid1");
            var rootRow = grid.RootTable.GetRowByGroup(0, rootLevel);
            rootRow.ExpandGroupRow();
            var subRow = rootRow.GetGroupChildRows()[subLevel];
            subRow.ExpandGroupRow();
            subRow.GetGroupChildRows()[subsubLevel].ExpandGroupRow();
            return;
        }&lt;/pre&gt;
&lt;p&gt;This way, only the groups that row is member of, are expanded.&lt;/p&gt;</description></item><item><title>How to programmatically expand group row?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-programmatically-expand-group-row/</link><pubDate>Thu, 16 Sep 2010 00:37:05 GMT</pubDate><dc:creator>handy@intersoftpt.com</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;Unfortunately, there is no method to expand all if you have more than 1 group levels.&lt;br /&gt;I think it is more easier if you handle this in client side.&lt;br /&gt;Please see my attached code. I am using on button click.&lt;/p&gt;&lt;pre&gt;  function Button1_onclick() {
            var grid = ISGetObject("WebGrid1");
            var currentRow = grid.GetSelectedObject().GetRowObject(); 
            currentRow.ExpandGroupRow(); // expand group row
            for (var i = 0; i &amp;lt; currentRow.GetGroupChildRows().length; i&amp;#43;&amp;#43;) {
                currentRow.GetGroupChildRows()[i].ExpandGroupRow();
            }
            return true;
                       
        }&lt;/pre&gt;
&lt;p&gt;Regards,&lt;br /&gt;Handy &lt;/p&gt;</description></item><item><title>How to programmatically expand group row?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-programmatically-expand-group-row/</link><pubDate>Wed, 15 Sep 2010 11:12:35 GMT</pubDate><dc:creator>Mladen.maras@combis.hr</dc:creator><description>&lt;p&gt;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:&lt;/p&gt;&lt;pre&gt;function NewItem() {
            var result = showModalDialogIframe("Edit.aspx", "", "dialogWidth=1000px;dialogHeight=800px");
            if (result == '1') {
                var grid = ISGetObject("WebGrid1");
                grid.SendCustomRequest();
            }
        }&lt;/pre&gt;
&lt;p&gt;On the server side in the WebGrid1_InitializePostBack event handler datasource is refreshed like this:&lt;/p&gt;&lt;pre&gt;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();
            }
        }&lt;/pre&gt;
&lt;p&gt;Grid has 3 levels of grouping. I want to show new item and coresponding groups expanded.&lt;/p&gt;
&lt;p&gt;I did something like this:&lt;/p&gt;&lt;pre&gt;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;
                    }
                }
            }
            
        }&lt;/pre&gt;
&lt;p&gt;However, it doesn't work, at least not completely. The way it works is shown in the attached screenshot. &lt;/p&gt;
&lt;p&gt;Is there an easier or better way to expand all the groups all the way down to the one row?&lt;/p&gt;</description></item></channel></rss>