A few ASP.NET 2.0 GridView Sorting Tips and Tricks

I saw a few interesting posts today that talked about ways to implement some sorting tips and tricks with the ASP.NET 2.0 GridView:

Mike has a nice post that walksthrough how to implement custom bi-directional sorting with the GridView.  Souri uses a similar approach to implement multi-column GridView sort semantics.

Teemu then has a cool post that shows how to implement "sort grouping" where you can sub-group/band row values within the GridView:

Hope this helps,

Scott

 

Published Saturday, February 11, 2006 10:22 AM by ScottGu

Comments

# re: A few ASP.NET 2.0 GridView Sorting Tips and Tricks

Sunday, February 12, 2006 4:10 PM by AsbjornM
No-one with an good tip about how to lock the header-row?, so it will stay in an fixed position when scrolling the contents?

# re: A few ASP.NET 2.0 GridView Sorting Tips and Tricks

Tuesday, February 14, 2006 5:00 PM by ns
The way i got the header row to stay fixed was to have the header row in its own table. The put the grid inside a div with overflow set to auto and specifing the height.
<%-- Start Heading -->
<TABLE id="Table6" cellSpacing="1" cellPadding="1" width="800" border="0" runat="server">
<TR class="clsHeading3">
<TD width="140">Column1</TD>
<TD width="194">Column2</TD>
<TD width="129">Column3</TD>
<TD width="90">Column4</TD>
<TD width="80">Column5</TD>
<TD width="80">Column6</TD>
<TD>Column7</TD>
</TR></TABLE>
<DIV style="OVERFLOW: auto; WIDTH: 820px; HEIGHT: 110px">
<asp:datagrid id="dgMeeting" runat="server" ShowHeader="False" CellSpacing="1" CellPadding="1"

# re: A few ASP.NET 2.0 GridView Sorting Tips and Tricks

Wednesday, February 15, 2006 4:01 AM by AsbjornM
Yeah, but then you miss the sorting functionality..

# 创建自定义排序用户界面

Saturday, August 26, 2006 12:04 PM by ksnoopy

显示大量已经按类别(不是很多)排序的数据但没有类别分界线,用户很难找到所需要的类别。例如,数据库中只有9个类别(8个不同的类别和1个null),共81种产品.现在用一个GridView列出所有产品,假设有用户对类别Seafood的产品感兴趣,她一定会按类别排序,把Seafood产品排列在一起.排序后,用户便寻找Seafood产品开始和结束的地方。虽然是按英文字母排列类别不难找到Seafood,但仍要花些时间在GridView寻找。为了进一步的区分类别,许多网站使用类别分界线这种排序用户界面来区别不同的类别。例如像图1中的分界线可以使用户很快地找到需要的类别。..

# re: A few ASP.NET 2.0 GridView Sorting Tips and Tricks

Tuesday, November 07, 2006 10:48 AM by Tom
Teemu's post etc. are good but one loses pagination ability, which is important, and you also lose sorting.

# re: A few ASP.NET 2.0 GridView Sorting Tips and Tricks

Monday, January 29, 2007 4:16 PM by Vishal

You can put linkbuttons into the seperately used header table. and then write sorting func on the linkbutton's click event.

The only problem I see with this fixed header solution is when you want to change your columns dynamically. (eg. Show an extra column based on the selection criteria)

Code Snippet:

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

<table style="LEFT: 3px; POSITION: relative; BORDER-COLLAPSE: collapse" borderColor="#000099"

cellSpacing="0" width="740" align="left" border="1">

<tr class="DataGrid_HeaderStyle" width="100%">

<td width="90"><asp:linkbutton id="lnkCol1" Runat="server" CommandName="Col1">Column 1</asp:linkbutton></td>

<td width="120"><asp:linkbutton id="lnkCol2" Runat="server" CommandName="Col2">Column 2</asp:linkbutton></td>

<td width="100"><asp:linkbutton id="lnkCol3" Runat="server" CommandName="Col3">Column 3</asp:linkbutton></td>

<td width="100"><asp:linkbutton id="lnkCol4" Runat="server" CommandName="Col4">Column 4</asp:linkbutton></td>

<td width="390"><asp:linkbutton id="lnkCol5" Runat="server" CommandName="Col5">Column 5</asp:linkbutton></td>

</tr>

</table>