I have a webgrid with 10 columns and 20 rows of data. The grouping style is set to outlook.
It seems that, if I group by a column, I am unable to expand the rows in the same method/event handler call.
For example, if I place a button on the page with the following event handler:
protected void Button1_Click(object sender, EventArgs e) { UltraWebGrid1.Columns[3].IsGroupByColumn = true; foreach (UltraGridRow r in UltraWebGrid1.Rows) { r.Expand(true); } }
I need to click the button twice in order that the rows are expanded.
Is this supposed to be happening??
Regards
AM
This could be something that is expected, since setting IsGroupByColumn just sets a property, while the actual grouping take place much later in the page life-cycle. So any expanded rows will be collapsed again for the group.
Is it possible to move the row exansion code at a later point in your page life cycle (say, OnPreRender) and see how it goes? You can also play with the InitializeLayout event of the grid and see if it is executed at a later point than the Button_Click event handler.
Ok.
I have changed the code to include a call to the PerformGroupRows method.
protected void Button1_Click(object sender, EventArgs e) { UltraWebGrid1.Columns[3].IsGroupByColumn = true; UltraWebGrid1.PerformGroupRows(); UltraWebGrid1.ExpandAll(true); }
The button click now works.
I then placed the code in an event handler for the PreRenderComplete event.
It now works on page load.
mjimenezch,
That's correct. Expanding rows on the server does not cause child data to be loaded. You would have to manually load all of the child data to expand each level.
The grid's built-in AJAX functionality ("XML load-on-demand") is meant to minimize how much information is loaded and sent. To expand all rows requires all rows and their children to be loaded. The two requirements can't both be accomplished.
Instead, turn off the grid's built-in AJAX functionality, and place it inside either a WebAsyncRefreshPanel or an UpdatePanel to get AJAX capabilities.
Cannot works with XML load on demand
Looks great. Thanks for sharing your solution in public forums - this will surely be helpful for other developers with this scenario.