Click here to Skip to main content
16,008,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am looking for the group gridview and calculate the aggregated function (MIN(score), AVG(score), MAX(score), etc..) within selected group. I need front end code only to solve the following problem:

I populated the gridview data based on dataset ds with query string in the front end. Here is my gridview data for school report look like:

School Test Score Min Max Avg

========================================================================

1 A 100

1 A 67
-------------------------------------------------------------------------
-------------------------------------------------------------------------
1 B 75

1 B 90

1 B 100
--------------------------------------------------------------------------
--------------------------------------------------------------------------
2 A 50
--------------------------------------------------------------------------
--------------------------------------------------------------------------
2 B 100

2 B 40
--------------------------------------------------------------------------
--------------------------------------------------------------------------
2 C 20
--------------------------------------------------------------------------
--------------------------------------------------------------------------
3 A 30

3 A 80
--------------------------------------------------------------------------
--------------------------------------------------------------------------
3 C 100


How do I can group above data with school and test and insert new above lines to display the MIN, MAX, AVG for each group? Then any results of above group aggregation are under 70, then highlight in red text. Any helps in coding this matter are much appreciated. Thanks in advance.
Posted

1 solution

Insted use this query to get data & bind it with normal gridview
select group, min(score), avg(score),max(score)
from table
group by group



Add this event to yoour gridview
XML
void Gridview1_RowDataBound(Object sender, GridViewRowEventArgs e)
  {

    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // cellno is column in which you score present
if( Convert.ToInt32(e.Row.Cells[cellno].Text) greterthan 70) 
// use symbol  insted of greterthan 
{
e.Row.Style.Add("background","red");
} 

    }

  }


Refer this link for color problem
Different row color in Gridview
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900