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

RadGrid Aggregate at run-time

5 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 06 Oct 2008, 09:00 AM
Hello,

I am using a RadGrid who's DataSource is a MySqlDataReader and the query is built based on POST's so although I can set the Column Headers, there is no data at design-time.

I want to be able to setup a couple of Aggregates so that when a user groups by a column it sum's a particular value.

I was hoping to do something like (in C#):

RadGrid1.Columns[1].Aggregate = <aggregate>.Sum;

but I cannot get to the Aggregate property.

Any ideas?

Thanks,

Andy

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Oct 2008, 10:25 AM
Hi Andy,

I hope you have set autogeneratedcolumns in the Grid. If so you can try the following code snippet in the ColumnCreated event to set the Aggregate property for the Grid columns.

CS:
 protected void RadGrid2_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (e.Column.ColumnType == GridBoundColumn) 
        { 
            if (e.Column.UniqueName == "Column UniqueName") 
            { 
                GridBoundColumn bndcol = (GridBoundColumn)col; 
                bndcol.Aggregate = GridAggregateFunction.Count; 
            } 
        } 
   } 


Thanks
Shinu.

0
Andy
Top achievements
Rank 1
answered on 07 Oct 2008, 11:06 AM

Hi Shinu,

I get an error when doing

if (e.Column.ColumnType == GridBoundColumn)  but not if i change it to if (e.Column.ColumnType == GridBoundColumn.thisExpr).

The error is:

Telerik.Web.UI.GridBoundColumn' is a 'type' but is used like a 'variable'

If I use the .thisExpr, i don't get the sum results? It might be because the e.Column.UniqueName doesn't exist, can you confirm that it's the field name in the MySqlDataReader?

If not, how else can I check it's the correct one?

Thanks,
Andy

0
Princy
Top achievements
Rank 2
answered on 07 Oct 2008, 11:47 AM
Hello Andy,

Try replacing the error creating line of code as shown below and see if it helps.
if (e.Column.ColumnType == "GridBoundColumn"). Also if you are using autogeneratedcolumns then the ColumnUniqueName will be the DataField of the column in the DataSource. If your columns are not autogenerated, then you will have to set the UniqueName property for the column in the aspx.

Thanks
Princy.

0
Andy
Top achievements
Rank 1
answered on 07 Oct 2008, 12:22 PM
Princy,

That worked but i think the problem is that the column is not a GridBoundColum, I've written out on the event the column type and unique name. The one I want Sum'd is FinancialValue. When I change the code to
if (e.ColumnType == "GridNumericColumn") I get a compiler error.

GridExpandColumn - ExpandColumn
GridBoundColumn - ConsultantName
GridBoundColumn - Notes
GridDateTimeColumn - DateTime
GridBoundColumn - ActivityName
GridNumericColumn - FinancialValue
GridBoundColumn - Source
GridDateTimeColumn - AddedDateTime
GridBoundColumn - AdditionalNotes
GridBoundColumn - DBSource

Thanks,

Andy
0
Andy
Top achievements
Rank 1
answered on 15 Oct 2008, 10:26 AM
Are there any other ideas here?
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Andy
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or