Ticket Q319187
Visible to All Users
Duplicate

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

Group By panel problem

created 14 years ago

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 ?

Comments (1)
Anatol (DevExpress) 14 years ago

    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:

    C#
    ... 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

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.