Playing a bit with GridView "Sort Grouping"

ASP.NET 2.0: Playing a bit with GridView "Sort Grouping"

I am on bit experiment mood today, so I did a little tryout to see what it requires to add so called "sort grouping" into GridView. E.g when you have tabular data in GridView and you sort it based on some criteria, you'd want to better express those distinct items, based on which the grid is sorted. Here's a few screenshots of what I did, to demonstrate what I mean.

You have a list of people, say having first name, last name and dob, and when it's in default sort based on last name,.grid would show something like

And the same sorted with first name

And with DOB in descending order

It's not very complicated to do. I did it originally for DataGrid in v1.x and then thought to try with gridView.  It requires a small bit knowledge of internal control structure of GridView (finding that with experimenting is possible,  no unnamed tools necessary ;-) ), and some code. You can download code for this sample from here

Note! I did it the ugly way and all the code in the sample is so far on Page and getting the distinct data (for separator headers) takes its text from BoundField's Cell's Text. In case you'd use Labels etc. in TemplateFields, you'd need to customize it a bit more.

Update! In case you want easier and reusable approach (mine was based on quick tests and then right away posting about it), Agrinei has posted a sample with source codes, and he posted in on comments on this post :

Hi,

I build a class that allow grouping and some other cool things. You can create groups and summaries with a few lines of code as you can see below:

// Group by ShipRegion
protected void Page_Load(object sender, EventArgs e)
{
   GridViewHelper helper = new GridViewHelper(this.GridView1);
   helper.RegisterGroup("ShipRegion", true, true);
   helper.ApplyGroupSort();
}

There's an online sample at
http://www.agrinei.com/gridviewhelper/sample/gridviewhelpersample_en.aspx

There's a draft for an english article at
http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm

You can get the latest version of the source files at
http://www.agrinei.com/gridviewhelper/gridviewhelpersample_en.zip  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值