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.
Complex Sorting and Paging ASP.Net and DWMX
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
I enjoy programming and someday plan on writing a book. I have been developing Enterprise web applications since 1999.
Comments
sorting
Great tutorial !
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?
VB Version
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
You must me logged in to write a comment.