Complex Sorting and Paging ASP.Net and DWMX

When I started programming I would scour the internet for good examples of code, You usually end up writing most yourself. I began programming <html> in 1999 and used notepad until I found out about Dreamweaver and Visual Studio and then I went crazy making sites. This article will teach the advanced and Intermediate users the great WYSIWYG of the Dreamweaver environment and the power of MX and .Net with a little homemade code to make it all come together for Complex ASP.Net Datagrid ASC/DESC sorting and paging.


Correct the code

At this point there are two things that need to be correct in the code:

AllowSorting="true"

OnSortCommand="Sort_Grid"

If these are correct we can go on.

In the codeview scroll down until you see the <column> tag:

<Columns>

      <asp:BoundColumn DataField="PID"

        HeaderText="PID"

        ReadOnly="true" SortExpression="PID"

        Visible="true" runat="server"/>

Right click the first column and open the "Editor":

The tag editor will show. To enable sorting you have to specify the "sort expression" which is the same as column heading name:

Click "OK". You see that dreamweaver has put the code into the column for you:

Now right click the other columns in the datagrid and make the same changes and make sure the columnid is the "SortExpression" after youre done your code should look like this:

<Columns>

      <asp:BoundColumn DataField="EmployeeID"

        HeaderText="EmployeeID"

        ReadOnly="true" SortExpression="EmployeeID"

        Visible="true" runat="server"/>

      <asp:BoundColumn DataField="LastName"

        HeaderText="LastName"

        ReadOnly="true" SortExpression="LastName"

        Visible="true" runat="server"/>

      <asp:BoundColumn DataField="FirstName"

        HeaderText="FirstName"

        ReadOnly="true" SortExpression="FirstName"

        Visible="true" runat="server"/>

      <asp:BoundColumn DataField="Title"

        HeaderText="Title"

        ReadOnly="true" SortExpression="Title"

        Visible="true" runat="server"/> </Columns>

WHEW! Ok now comes the fun part. Scroll up until you see this code:

<MM:PageBind runat="server" PostBackBind="true" />

<html>

create a space between them and copy and paste this code (C# only. if you are using VB then you will have to change the code syntax):

This script is called by the "OnSortCommand" in the DataGrid. I created this code to easily allow ASC and DESC sorting of the columns! WOW! Note: It also works with Visual Studio .Net

Your code should look like this:

Now lets take it for a test drive hit F12! You should see:

CONGRATULATIONS! you now have a datagrid that enables paging and ASC/DESC Column Sorting.

Charles Stratton

Charles StrattonI enjoy programming and someday plan on writing a book. I have been developing Enterprise web applications since 1999.

See All Postings From Charles Stratton >>

Comments

sorting

December 17, 2003 by Paul Anderson
Excellent article....this has helped me with designing a search results page for my companies website.

Great tutorial !

December 17, 2003 by Marcellino Bommezijn

Charles,

Finally there is someone that can present a ASP.NET tutorial which gives me the 'push' to actually get started with moving to ASP.NET.

Hope you have some more of these tutorials in 'the magic head' covering ASP.NET in DWMX.

Thanks

 

 

Thanks - VB .NET examples?

April 1, 2005 by Liam Cassidy
Great article - thank you! I don't use (or know) C#... anyone able to post the VB .NET alternatives?

VB Version

May 12, 2005 by Stephen Davidson

Great article...i was able to follow it and convert it to VB .Net, if anyone wants the code for this drop me a line.

Cheers,

Stephen

See all 9 Comments

You must me logged in to write a comment.