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

 

5 Comments

  • 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?

  • 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"

  • Yeah, but then you miss the sorting functionality..

  • Teemu's post etc. are good but one loses pagination ability, which is important, and you also lose sorting.

  • 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:
    ============


    Column 1
    Column 2
    Column 3
    Column 4
    Column 5


Comments have been disabled for this content.