使用数据集在ASP.NET中对Gridview进行分组! [英] Group Gridview in ASP.NET using dataset!

查看:73
本文介绍了使用数据集在ASP.NET中对Gridview进行分组!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在寻找组gridview并计算选定组内的聚合函数(MIN(分数),AVG(分数),MAX(分数)等).我只需要前端代码即可解决以下问题:

我在前端根据查询字符串填充了基于数据集ds的gridview数据.这是我用于学校报告的gridview数据,如下所示:

学校测验分数最小最大平均数

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

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


如何将以上数据与学校进行分组并进行测试,并插入新的上述行以显示每个组的 MIN,MAX,AVG?然后,以上组聚集的任何结果均低于70,然后以红色文本突出显示.非常感谢您对此代码进行编码.在此先感谢您.

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.

推荐答案

Insted使用此查询来获取数据&将其与普通的gridview绑定
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




将此事件添加到您的gridview




Add this event to yoour gridview

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");
} 

    }

  }



请参阅此链接以解决颜色问题
Gridview中的行颜色不同



Refer this link for color problem
Different row color in Gridview


这篇关于使用数据集在ASP.NET中对Gridview进行分组!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆