- 浏览: 1054004 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
Tracyer:
你也太强了吧,请问楼主邮箱多少,请教一下plan_9
Plan 9安装Go -
lipengfeng:
不兼容2007
asp.net使用组件koogra读取Excel数据批量上传导入 -
jamie.wang:
博主是mm?
男人四十 -
niwowl:
count那去了!
通过java提供的URL类包读取网上的文件 -
uuid198909:
代码风格啊,博主
高并发系统设计
资料链接
http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm
GridView: Creating groups and summaries with 2 lines of code
Site about multilingual website development launched:www.MultiLanguageWebSites.com |
GridView has a lot of improvements over the DataGrid but it still lacks some very important features. A recurring requirement not available in the GridView is to create groups and summaries. To create summaries we can easily code the RowDataBound event. Grouping is a more complex task, and involves more coding and debugging. But when we need to combine these two features the things really start to get messy. With this in mind I have implemented the GridViewHelper, as the name suggests, a helper class to aid the creation of groups and summaries.
Using the GridViewHelper
Below we will see some GridViewHelper samples. First we show the grid to which the groups and summaries will be created. The sample data comes from Northwind database, with a few modifications:
NM | Old World Delicatessen | 10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
NM | Old World Delicatessen | 10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
NM | Old World Delicatessen | 10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
NM | Old World Delicatessen | 10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
OR | Save-a-lot Markets | 10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
OR | Save-a-lot Markets | 10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
OR | Save-a-lot Markets | 10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
OR | Gourmet Lanchonetes | 10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
OR | Split Rail Beer & Ale | 10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
OR | Split Rail Beer & Ale | 10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
OR | Lazy K Kountry Store | 10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
NM | Old World Delicatessen | 10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
NM | White Clover Markets | 10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
NM | White Clover Markets | 10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
NM | White Clover Markets | 10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
To create a summary for the ItemTotal column we need only the promised 2 lines of code:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
helper.RegisterSummary("ItemTotal",SummaryOperation.Sum);
}
First we create the GridViewHelper setting the grid in which it will act in the constructor. Then we register the summary specifying the column name and the summary operation to be performed. The result is below:
NM | Old World Delicatessen | 10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
NM | Old World Delicatessen | 10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
NM | Old World Delicatessen | 10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
NM | Old World Delicatessen | 10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
OR | Save-a-lot Markets | 10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
OR | Save-a-lot Markets | 10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
OR | Save-a-lot Markets | 10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
OR | Gourmet Lanchonetes | 10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
OR | Split Rail Beer & Ale | 10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
OR | Split Rail Beer & Ale | 10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
OR | Lazy K Kountry Store | 10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
NM | Old World Delicatessen | 10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
NM | White Clover Markets | 10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
NM | White Clover Markets | 10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
NM | White Clover Markets | 10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
US$ 20.550,10 |
In this sample a new line was added to display the summary. Another option is to use the footer row to display the summary instead of creating a new one. When a new row is added to the grid, only the required cells to display the summarized columns are created. Using the footer, all the cells are created. In case of group summaries, generation of all cells or only the needed cells is a group attribute.
Now we will create a group. The code is shown below:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
helper.RegisterGroup("ShipRegion",true,true);
helper.ApplyGroupSort();
}
The first parameter of RegisterGroup method defines the columns to which the group must be created. It's also possible to create a composite group, consisting of an array of columns. The second parameter specifies if the group is automatic. In this case a new row will be created automatically for the group header. The third parameter specifies if the group columns must be hidden. The ApplyGroupSort method sets the sort expression of the grid as being the group columns, in this case, ShipRegion. This is required to grouping works properly, except if the data comes ordered from database.
In the above sample the column ShipRegion have been hidden:
NM | |||||
Old World Delicatessen | 10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
Old World Delicatessen | 10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
Old World Delicatessen | 10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
Old World Delicatessen | 10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
Old World Delicatessen | 10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
White Clover Markets | 10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
White Clover Markets | 10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
White Clover Markets | 10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
OR | |||||
Save-a-lot Markets | 10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
Save-a-lot Markets | 10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
Save-a-lot Markets | 10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
Gourmet Lanchonetes | 10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
Split Rail Beer & Ale | 10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
Split Rail Beer & Ale | 10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
Lazy K Kountry Store | 10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
Let's make something more interesting, let's add a summary to the created group. We need just one more line to register the summary to the group:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
helper.RegisterGroup("ShipRegion",true,true);
helper.RegisterSummary("ItemTotal",SummaryOperation.Sum,"ShipRegion");
helper.ApplyGroupSort();
}
This time, the RegisterSummary method takes another parameter. The parameter specifies the name of the group to which the summary must be created. Group name is automatically generated from the group column names. If the group has only one column, group name will be the name of that column. If the group has more than one column, the group name will be the ordered concatenation of the columns that composes the group, joined with a plus sign ("+"): "ShipRegion+ShipName".
We can see below the grid with grouping and a summary for the group:
NM | |||||
Old World Delicatessen | 10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
Old World Delicatessen | 10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
Old World Delicatessen | 10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
Old World Delicatessen | 10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
Old World Delicatessen | 10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
White Clover Markets | 10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
White Clover Markets | 10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
White Clover Markets | 10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
US$ 18.465,10 | |||||
OR | |||||
Save-a-lot Markets | 10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
Save-a-lot Markets | 10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
Save-a-lot Markets | 10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
Gourmet Lanchonetes | 10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
Split Rail Beer & Ale | 10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
Split Rail Beer & Ale | 10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
Lazy K Kountry Store | 10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
US$ 2.085,00 |
It's possible to create more than one group in the grid, simulating a hierarchical grouping, as seen below:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
helper.RegisterGroup("ShipRegion",true,true);
helper.RegisterGroup("ShipName",true,true);
helper.ApplyGroupSort();
}
Result:
NM | ||||
Old World Delicatessen | ||||
10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
White Clover Markets | ||||
10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
OR | ||||
Lazy K Kountry Store | ||||
10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
Gourmet Lanchonetes | ||||
10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
Split Rail Beer & Ale | ||||
10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
Save-a-lot Markets | ||||
10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
Visualization is compromised when there is more than one group. GridViewHelper has events to allow easy implementation of visual or functional adjusts. The list of events follows below:
GroupStart | Occurs when a new group starts, it means, when new values are found in the group column. |
GroupEnd | Occurs in the last row of the group |
GroupHeader | Occurs when an automatic header row is added for the group. The event is not triggered if the group is not automatic. |
GroupSummary | Occurs when the summary row is generated for the group. The event is not triggered if the group is not automatic, but will be triggered if the group is a suppression group (will be seen later on). |
GeneralSummary | Occurs after the general summaries be calculated. If the summary is automatic the event occurs after the summary row be added and after the summary values be placed in the row. |
FooterDataBound | Occurs in the footer databinding. |
With a few more lines of code we can improve the visual aspect of the grid:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
helper.RegisterGroup("ShipRegion",true,true);
helper.RegisterGroup("ShipName",true,true);
helper.GroupHeader+=newGroupEvent(helper_GroupHeader);
helper.ApplyGroupSort();
}
privatevoidhelper_GroupHeader(stringgroupName,object[]values,GridViewRowrow)
{
if(groupName=="ShipRegion")
{
row.BackColor=Color.LightGray;
row.Cells[0].Text=" "+row.Cells[0].Text;
}
elseif(groupName=="ShipName")
{
row.BackColor=Color.FromArgb(236,236,236);
row.Cells[0].Text=" "+row.Cells[0].Text;
}
}
The grid after the cosmetics:
NM | ||||
Old World Delicatessen | ||||
10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
White Clover Markets | ||||
10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
OR | ||||
Lazy K Kountry Store | ||||
10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
Gourmet Lanchonetes | ||||
10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
Split Rail Beer & Ale | ||||
10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
Save-a-lot Markets | ||||
10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
More grouping options
There are two more interesting samples. The first presents a composite group. The second defines a suppress group, that has the same behavior of the sql GROUP BY clause. The repeating values are suppressed, and a summary operation is performed on the other columns.
Below we can see the code and the grid appearance for the composite group:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
string[]cols=newstring[2];
cols[0]="ShipRegion";
cols[1]="ShipName";
helper.RegisterGroup(cols,true,true);
helper.ApplyGroupSort();
}
NM - Old World Delicatessen | ||||
10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
NM - White Clover Markets | ||||
10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
OR - Lazy K Kountry Store | ||||
10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
OR - Gourmet Lanchonetes | ||||
10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
OR - Split Rail Beer & Ale | ||||
10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
OR - Save-a-lot Markets | ||||
10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
We can add a summary to the group. This time we will define an average operation and add a label to indicate the operation:
{
GridViewHelper helper=newGridViewHelper(this.GridView1);
string[]cols=newstring[2];
cols[0]="ShipRegion";
cols[1]="ShipName";
helper.RegisterGroup(cols,true,true);
helper.RegisterSummary("ItemTotal",SummaryOperation.Avg,"ShipRegion+ShipName");
helper.GroupSummary+=newGroupEvent(helper_GroupSummary);
helper.ApplyGroupSort();
}
privatevoidhelper_GroupSummary(stringgroupName,object[]values,GridViewRowrow)
{
row.Cells[0].HorizontalAlign=HorizontalAlign.Right;
row.Cells[0].Text="Average";
}
NM - Old World Delicatessen | ||||
10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
Average | US$ 3.422,30 | |||
NM - White Clover Markets | ||||
10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
Average | US$ 451,20 | |||
OR - Lazy K Kountry Store | ||||
10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
Average | US$ 108,00 | |||
OR - Gourmet Lanchonetes | ||||
10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
Average | US$ 155,00 | |||
OR - Split Rail Beer & Ale | ||||
10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
Average | US$ 561,00 | |||
OR - Save-a-lot Markets | ||||
10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
Average | US$ 233,33 |
The last sample will create a suppress group. It's important to mention that if a suppress group is defined, no other group may be created. In the same way, if there is already a group defined, we can't create a suppress group and an exception will be raised if we try it.
Below we can see the code and the grid appearance for the suppress group:
{
GridViewHelperhelper=newGridViewHelper(this.GridView1);
helper.SetSuppressGroup("ShipName");
helper.RegisterSummary("Quantity",SummaryOperation.Sum,"ShipName");
helper.RegisterSummary("ItemTotal",SummaryOperation.Sum,"ShipName");
helper.ApplyGroupSort();
}
Lazy K Kountry Store | 9 | US$ 108,00 | ||||
Gourmet Lanchonetes | 20 | US$ 155,00 | ||||
Old World Delicatessen | 147 | US$ 17.111,50 | ||||
White Clover Markets | 59 | US$ 1.353,60 | ||||
Split Rail Beer & Ale | 66 | US$ 1.122,00 | ||||
Save-a-lot Markets | 33 | US$ 700,00 |
No value is displayed for the columns that don't have a summary operation defined. This makes sense because GridViewHelper doesn't know how to proceed to summarize the values found in the group rows to a unique value. This reminds the certain known message:
"Column 'column_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
It doesn't make sense to display the columns that don't have a summary operation, and to hide them we need to call a method:
{
GridViewHelperhelper=newGridViewHelper(this.GridView1);
helper.SetSuppressGroup(rdBtnLstGroup.SelectedValue);
helper.RegisterSummary("Quantity",SummaryOperation.Sum,"ShipName");
helper.RegisterSummary("ItemTotal",SummaryOperation.Sum,"ShipName");
helper.SetInvisibleColumnsWithoutGroupSummary();
helper.ApplyGroupSort();
}
I know, it's a big big name! The resulting grid can be seen below:
Lazy K Kountry Store | 9 | US$ 108,00 |
Gourmet Lanchonetes | 20 | US$ 155,00 |
Old World Delicatessen | 147 | US$ 17.111,50 |
White Clover Markets | 59 | US$ 1.353,60 |
Split Rail Beer & Ale | 66 | US$ 1.122,00 |
Save-a-lot Markets | 33 | US$ 700,00 |
Summary operations
GridViewHelper has 3 built-in summary operations: sum, average and row count. A very useful feature is the possibility of define custom summary operations. To achieve this we need to provide two methods to the GridViewHelper. A method will be called for each row found in the grid (or group) and the other will be called to retrieve the result of the summary operation. Below we have a sample of a custom summary operation. The semi-dummy operation will return the minimum value found:
protectedvoidPage_Load(objectsender,EventArgse)
{
GridViewHelperhelper=newGridViewHelper(this.GridView1);
helper.RegisterSummary("Quantity",SaveQuantity,GetMinQuantity);
}
privatevoidSaveQuantity(stringcolumn,stringgroup,objectvalue)
{
mQuantities.Add(Convert.ToInt32(value));
}
privateobjectGetMinQuantity(stringcolumn,stringgroup)
{
int[]qArray=newint[mQuantities.Count];
mQuantities.CopyTo(qArray);
Array.Sort(qArray);
returnqArray[0];
}
In the code above we can see the required methods signatures. Both receive the summarized group and column names. If the summary is not relative to a group, the group parameter will be null. The method that is called for each row found in the grid, receives also the value of the column in the current row.
The resulting grid can be seen below :
NM | Old World Delicatessen | 10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
NM | Old World Delicatessen | 10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
NM | Old World Delicatessen | 10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
NM | Old World Delicatessen | 10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
OR | Save-a-lot Markets | 10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
OR | Save-a-lot Markets | 10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
OR | Save-a-lot Markets | 10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
OR | Gourmet Lanchonetes | 10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
OR | Split Rail Beer & Ale | 10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
OR | Split Rail Beer & Ale | 10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
OR | Lazy K Kountry Store | 10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
NM | Old World Delicatessen | 10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
NM | White Clover Markets | 10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
NM | White Clover Markets | 10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
NM | White Clover Markets | 10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
4 |
Limitations
In one sample we said that we cansimulatea hierarchical grouping. Although the grid appears to present a hierarchical grouping, the actual implementation isn't hierarchical. There's no group or subgroup. There are only sequentially registered groups. This becomes a problem if we need to create a summary for an inner group. Below we can see what happens in this situation:
{
GridViewHelperhelper=newGridViewHelper(this.GridView1);
helper.RegisterGroup("ShipRegion",true,true);
helper.RegisterGroup("ShipName",true,true);
helper.RegisterSummary("ItemTotal",SummaryOperation.Sum,"ShipName");
helper.RegisterSummary("ItemTotal",SummaryOperation.Sum);
helper.GroupSummary+=newGroupEvent(helper_Bug);
helper.ApplyGroupSort();
}
privatevoidhelper_Bug(stringgroupName,object[]values,GridViewRowrow)
{
if(groupName==null)return;
row.BackColor=Color.Bisque;
row.Cells[0].HorizontalAlign=HorizontalAlign.Center;
row.Cells[0].Text="[Summaryfor"+groupName+""+values[0]+"]";
}
NM | ||||
Old World Delicatessen | ||||
10922 | Alice Mutton | 15 | US$ 39,00 | US$ 585,00 |
10922 | Teatime Chocolate Biscuits | 35 | US$ 4,50 | US$ 157,50 |
10925 | Inlagd Sill | 25 | US$ 19,00 | US$ 475,00 |
10925 | Filo Mix | 12 | US$ 7,00 | US$ 84,00 |
10981 | Côte de Blaye | 60 | US$ 263,50 | US$ 15.810,00 |
[ Summary for ShipName Old World Delicatessen ] | US$ 17.111,50 | |||
White Clover Markets | ||||
10989 | Grandma's Boysenberry Spread | 40 | US$ 25,00 | US$ 1.000,00 |
10989 | Queso Cabrales | 15 | US$ 21,00 | US$ 315,00 |
10989 | Camembert Pierrot | 4 | US$ 9,65 | US$ 38,60 |
OR | ||||
[ Summary for ShipName White Clover Markets ] | US$ 1.353,60 | |||
Lazy K Kountry Store | ||||
10969 | Spegesild | 9 | US$ 12,00 | US$ 108,00 |
[ Summary for ShipName Lazy K Kountry Store ] | US$ 108,00 | |||
Gourmet Lanchonetes | ||||
10959 | Rhönbräu Klosterbier | 20 | US$ 7,75 | US$ 155,00 |
[ Summary for ShipName Gourmet Lanchonetes ] | US$ 155,00 | |||
Split Rail Beer & Ale | ||||
10961 | Filo Mix | 6 | US$ 7,00 | US$ 42,00 |
10961 | Lakkalikööri | 60 | US$ 18,00 | US$ 1.080,00 |
[ Summary for ShipName Split Rail Beer & Ale ] | US$ 1.122,00 | |||
Save-a-lot Markets | ||||
10935 | Chai | 21 | US$ 18,00 | US$ 378,00 |
10935 | Carnarvon Tigers | 4 | US$ 62,50 | US$ 250,00 |
10935 | Tunnbröd | 8 | US$ 9,00 | US$ 72,00 |
[ Summary for ShipName Save-a-lot Markets ] | US$ 700,00 | |||
US$ 20.550,10 |
As we can see, the summary is created after the header of the outer group. This occurs because the event sequence is:
Group1_Start
Group1_End
Group2_Start
Group2_End
To a hierarchical grouping, the event sequence should be:
Group1_Start
Group2_Start
Group2_End
Group1_End
Implementation
GridViewHelper was implemented as a standalone class instead of an inherited class. This makes possible to use the GridViewHelper with any GridView, and doesn't force the developer to inherit a specific GridView, what could affect the classes design. There's another four classes in the solution:GridViewSummary, GridViewGroup, GridViewSummaryList and GridViewGroupList. The "list" classes were created to allow access by a string indexer: helper.GeneralSummaries["ItemTotal"].Value.
When the GridViewHelper is created, a reference to the target GridView is saved, and the RowDataBound event is bound to the method that does the hard work:
{
this.mGrid=grd;
this.useFooter=useFooterForGeneralSummaries;
this.groupSortDir=groupSortDirection;
this.mGeneralSummaries=newGridViewSummaryList();
this.mGroups=newGridViewGroupList();
this.mGrid.RowDataBound+=newGridViewRowEventHandler(RowDataBoundHandler);
}
Some methods used i
相关推荐
Android GridView分组显示、带dock标题,带下拉刷新
使用ASPxGridview分页功能可以实现对数据的分组查看功能以及实现如何对gridview进行分页
android GridView分组 convertview可重用 可用于 图片相册 日期分组 内存消耗低
Gridview结合ajax异步数据分组范例
GridView分组显示StickyGridHeaders,GridView分组显示StickyGridHeaders
主要介绍了Winform中GridView分组排序功能实现方法,以实例形式详细说明了分组排序的实现方法,并附带完整的DBHelp类代码,是非常实用的技巧,需要的朋友可以参考下
GridView各功能实例GridView各功能实例GridView各功能实例
功能强大自定义GridView控件全源码
本实例提供了经典的C#开发工具GridView控件的分组显示和列累计计算。
GRIDVIEW实现EXCEL列冻结功能, 简单,实用。易扩装.易理解...
利用GridView实现单选功能的demo
GridView实现正反双向排序功能
Gridview 分组显示,支持停靠title,上拉下拉刷新,
android 滑动效果 比较实用的 图片浏览器开发,gridview 和 gallary
gridview分页 gridview绑定数据 gridview分页 gridview checkbox 此代码有:表头表尾,导入导出,多层嵌套,分页排序,结合控件,设置属性,无代码,增除删改,主键索引 下载即用,不需安装数据库,真是个方便啊!
本程序,详细的阐述了如何实现gridview的排序和分页功能。本程序无任何错误,下载即可运行
本实例,详细的讲解了gridview的各种编辑功能,绝对是你学习gridview用法的理想资料。本程序无任何错误,下载即可运行
GridView实现联系人功能,包含GridView合并,修改,等一些功能 GridView实现联系人功能,包含GridView合并,修改,等一些功能 GridView实现联系人功能,包含GridView合并,修改,等一些功能
msdn里面关于的GridView介绍