Hi,
I implemented the optimization shown in http://devexpress.com/issue=B199094 . This works perfect. However the group by panel somehow doesn't like it and generates an error when used (object reference not set). Is there a solution for this?
regards,
Martin
ps. any chance this optimization becomes default behavior in 11.1 ?
We have closed this ticket because another page addresses its subject:
Performance.Web - Use data-specific column types instead of data item templates whenever possible
Hello Martin,
The problem occurs because the GroupContentTemplate used for group rows uses the column's DataItemTemplate to create controls. The easiest way to resolve this problem is to clear the ASPxGridListEditor.Grid.Templates.GroupRowContent property. You can also implement a custom GroupContentTemplate based on the existing one, as shown below:
... editor.Grid.Templates.GroupRowContent = new MyGroupContentTemplate(); } public class MyGroupContentTemplate : ITemplate { #region ITemplate Members public void InstantiateIn(Control container) { GridViewGroupRowTemplateContainer groupRowTemplateContainer = (GridViewGroupRowTemplateContainer)container; GridViewDataColumnWithInfo column = groupRowTemplateContainer.Column as GridViewDataColumnWithInfo; string caption = column.Caption; Control valueControl = new Control(); if (column.Model.GroupInterval == GroupInterval.None && column.DataItemTemplate != null) { GridViewDataItemTemplateContainer dummyContainer = new GridViewDataItemTemplateContainer(groupRowTemplateContainer.Grid, 0, groupRowTemplateContainer.VisibleIndex, column); column.DataItemTemplate.InstantiateIn(dummyContainer); for (int i = 0; i < dummyContainer.Controls.Count; i++) { valueControl.Controls.AddAt(i, dummyContainer.Controls[i]); } dummyContainer.Controls.Clear(); dummyContainer.Dispose(); } else { if (groupRowTemplateContainer.KeyValue != null && groupRowTemplateContainer.KeyValue.GetType() == typeof(DateTime) && ((DateTime)groupRowTemplateContainer.KeyValue) == DateTime.MinValue) { valueControl.Controls.Add(new LiteralControl(string.Empty)); } else { valueControl.Controls.Add(new LiteralControl(groupRowTemplateContainer.GroupText)); } } string summary = groupRowTemplateContainer.SummaryText; groupRowTemplateContainer.Controls.Add(LayoutGroupInfo(caption, valueControl, summary)); } #endregion public virtual Control LayoutGroupInfo(string caption, Control valueControl, string summary) { Table table = new Table(); table.Rows.Add(new TableRow()); table.Rows[0].Cells.Add(new TableCell()); table.Rows[0].Cells.Add(new TableCell()); table.Rows[0].Cells.Add(new TableCell()); table.Rows[0].Cells[0].Text = caption + ": "; table.Rows[0].Cells[1].Controls.Add(valueControl); table.Rows[0].Cells[2].Text = summary; return table; } }
I have also created a corresponding bug report: ASPxGridListEditor - GroupContentTemplate throws NullReferenceException when the column's DataItemTemplate is empty. We will research whether this template causes any problems and if not, change the default template.
As for using a similar approach to improve performance by default, I have created a corresponding suggestion, but, most likely, it will not be implemented in 11.1: Performance.Web - Do not use columns' data item templates when this is not necessary.
Thanks,
Anatol