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

[Solved] GridView Totals template

9 Answers 187 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rama
Top achievements
Rank 1
Rama asked on 09 Feb 2011, 05:22 PM
Hi,

I'm planning to do the totals/aggregate function at code behind. do you've any sample codes for this?

My code:

  GridViewDataColumn gridColumn =   new GridViewDataColumn{Header = key};
                 Binding bin = new Binding(string.Format("Key.Attributes[{0}]", key));
                 gridColumn.DataMemberBinding = bin;
                 TraderMeasureSeriesGrid.Columns.Add(gridColumn);

I would like to attach  AggregateFunctions from code behind. how can I set this?

<telerik:GridViewDataColumn.AggregateFunctions>

         <telerik:SumFunction Caption="Sum: "  SourceField="TotalCost" FunctionName="Sum" />                      
    </
telerik:GridViewDataColumn.AggregateFunctions>

Also, How can i Set footer and header template?

                          <telerik:GridViewDataColumn.Footer>

                              <telerik:RadButton Content="Show smallest UnitPrice" Click="Button_Click" Margin="5,0" />

                           </telerik:GridViewDataColumn.Footer>

                            <telerik:GridViewDataColumn.GroupHeaderTemplate>

                                <DataTemplate>

                                    <TextBlock Foreground="Green" Text="{Binding Group.Key}" />

                                </DataTemplate>

                            </telerik:GridViewDataColumn.GroupHeaderTemplate>

Thanks in advance,

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Feb 2011, 05:41 PM
Hello,

 You can set it exactly in the same way as in XAML. Just create desired function and add it in the column aggregate functions. 

Greetings,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Rama
Top achievements
Rank 1
answered on 09 Feb 2011, 05:51 PM
Thanks for the quick reply but AggregateFunction is abstract class and I can't find  a way to create new AggregateFunction in code behind. do you've any example?

Thanks
0
Vlad
Telerik team
answered on 10 Feb 2011, 08:13 AM
Hello,

You should create SumFunction exactly as in XAML.

Best wishes,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Rama
Top achievements
Rank 1
answered on 10 Feb 2011, 08:21 AM
Hi Vlad,

I tried all possible scenarios hence posted this question. if it's same as xaml, can you attach code snippet? we're evaluating Telerik versus DevExpress controls. you quick response will be appreciated.

Thanks
0
Vlad
Telerik team
answered on 10 Feb 2011, 08:33 AM
Hello,

 Here is the code - extremely simple as you can see:

var column = new GridViewDataColumn();
column.AggregateFunctions.Add(new SumFunction() { SourceField = "YourSourceFiled" });



Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Rama
Top achievements
Rank 1
answered on 10 Feb 2011, 08:37 AM
Thanks again for your quick response. I'll test this now.
0
Rama
Top achievements
Rank 1
answered on 10 Feb 2011, 01:03 PM
Hi Vlad,

When I do the following I get zero sum:

   gridColumn.AggregateFunctions.Add(new SumFunction() {SourceField = measure,FunctionName = "Sum", SourceFieldType = Type.GetType("System.Int32")});

do you know why? no exception no error simply zero. Please note that I'm not using any other celltemplate, footer or header templates:

   GridViewDataColumn gridColumn = new GridViewDataColumn {Header = measure};
                gridColumn.DataMemberBinding = bin;
                    gridColumn.AggregateFunctions.Add(new SumFunction() {SourceField = measure,FunctionName = "Sum", SourceFieldType = Type.GetType("System.Int32")});
                TraderMeasureSeriesGrid.Columns.Add(gridColumn);

Please let me know how to debug Aggregate functions like above to check where I'm going wrong.

Thanks
0
Rama
Top achievements
Rank 1
answered on 10 Feb 2011, 01:14 PM
Hi, Please note that my data is valid and contains all integers so it's not a data issue
0
Rama
Top achievements
Rank 1
answered on 10 Feb 2011, 03:06 PM
Resolved myself. it needs same databinding path as Binding.
Tags
GridView
Asked by
Rama
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rama
Top achievements
Rank 1
Share this question
or