This is a migrated thread and some comments may be shown as answers.

[Solved] GridGroupByExpression Error on RadGrid

4 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 21 Feb 2013, 03:52 PM
I have a RadGrid that uses a SqlDataSource and the column are auto-generated by the data source. Each column represents a date between a selectable date range. The grid works fine except if I want to use GridGroupByExpression. If that is enabled, I get an message stating (for example):

Column '2013-02-19' does not belong to table .

I'm not performing a postback and I don't have anything being called during Page Load or Init. The fields that are aggregated are whole integers.The columns displayed would be something like, 2013-02-19, 2013-02-20, 2013-20-21... again, this works fine if I don't use the grid group by expression and I can group manually... I'm trying to have the grouping by default.

Below is my ASPX:
<telerik:RadGrid ID="RG_SLASummary" runat="server" CellSpacing="0" DataSourceID="SDS_SLASummary" GridLines="None" ShowGroupPanel="True" style="margin:10px" ShowFooter="True" Height="750" OnColumnCreated="RG_SLASummary_ColumnCreated">
    <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True">
        <Selecting AllowRowSelect="True" />
        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
    <AlternatingItemStyle Width="100px" />
    <GroupHeaderItemStyle Width="100px" />
    <GroupingSettings RetainGroupFootersVisibility="true" />
    <MasterTableView DataSourceID="SDS_SLASummary" ShowGroupFooter="true">
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="Region" FieldAlias="Region" />
                    <telerik:GridGroupByField FieldName="Status" FieldAlias="Status" />
                    <telerik:GridGroupByField FieldName="Scheduler" FieldAlias="Scheduler" />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="Region" />
                    <telerik:GridGroupByField FieldName="Status" />
                    <telerik:GridGroupByField FieldName="Scheduler"  />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
        <SortExpressions>
            <telerik:GridSortExpression FieldName="Region" SortOrder="Ascending" />
            <telerik:GridSortExpression FieldName="Status" SortOrder="Ascending" />
            <telerik:GridSortExpression FieldName="Scheduler" SortOrder="Ascending" />
        </SortExpressions>
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"/>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"/>
            <ItemStyle Width="20px" />
        </ExpandCollapseColumn>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <EditItemStyle Width="100px" />
    <FilterItemStyle Width="100px" />
    <ActiveItemStyle Width="100px" />
    <ItemStyle Width="100px" />
    <SelectedItemStyle Width="100px" />
    <FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
 
<asp:SqlDataSource ID="SDS_SLASummary" runat="server" ConnectionString="<%$ ConnectionStrings:CWFMO %>" SelectCommand="ESP_SchedulerSLASummary" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="RDP_StartDate" DbType="Date" Name="startdate" PropertyName="SelectedDate" />
        <asp:ControlParameter ControlID="RDP_EndDate" DbType="Date" Name="enddate" PropertyName="SelectedDate" />
    </SelectParameters>
</asp:SqlDataSource>

Below is my code behind:
protected void RG_SLASummary_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column is GridNumericColumn)
            {
                GridNumericColumn gridNumericColumn = (GridNumericColumn)e.Column;
                gridNumericColumn.Aggregate = GridAggregateFunction.Sum;
            }
        }


4 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 21 Feb 2013, 05:09 PM
I've also tried removing the dashes in the field name, changing up group by fields... it either works (but then groups by every date when I need to sum the numbers) or throws the same error... any ideas?
0
Matt
Top achievements
Rank 1
answered on 21 Feb 2013, 05:47 PM
So far, setting the GridBoundColumns works... but it breaks the data model... so I'm off to look at how to dynamic add the columns in code behind? 
0
Matt
Top achievements
Rank 1
answered on 22 Feb 2013, 04:21 PM
Either I asked a real lame question or no body knows. I found that I have to add the columns dynamically, something like this...

DateTime startDate = Convert.ToDateTime(RDP_StartDate.SelectedDate);
            DateTime endDate = Convert.ToDateTime(RDP_EndDate.SelectedDate);
            TimeSpan timeSpan = (endDate - startDate);
            int c = 0;
            while (c <= timeSpan.Days)
            {
                if (startDate.AddDays(c).DayOfWeek != DayOfWeek.Saturday && startDate.AddDays(c).DayOfWeek != DayOfWeek.Sunday && !IsHoliday(startDate.AddDays(c).ToShortDateString()))
                {
                    GridBoundColumn gridBoundColumn = new GridBoundColumn();
                    RG_SLASummary.MasterTableView.Columns.Add(gridBoundColumn);
                    gridBoundColumn.DataField = startDate.AddDays(c).ToString("yyyyMMdd");
                    gridBoundColumn.HeaderText = startDate.AddDays(c).ToString("yyyyMMdd");
                    gridBoundColumn.Aggregate = GridAggregateFunction.Sum;
                    gridBoundColumn.FooterAggregateFormatString = "{0}";
                    gridBoundColumn.HeaderStyle.Width = Unit.Pixel(50);
                    gridBoundColumn.FooterStyle.Font.Bold = true;
                    gridBoundColumn.FooterStyle.HorizontalAlign = HorizontalAlign.Center;
                    gridBoundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    gridBoundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    gridBoundColumn.ItemStyle.ForeColor = Utility.Red;
                    gridBoundColumn.FooterStyle.ForeColor = Utility.Red;
                }
                c++;
            }

Thank you for viewing.
0
Maria Ilieva
Telerik team
answered on 26 Feb 2013, 01:19 PM
Hello Matt,

Please try setting the Aggregate property of the column in the PreRender event instead of the ColumnCreated in and see whether if it works.

All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or