Scott on Writing

Musings on technical writing...

The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online!

Four new “Working with Data in ASP.NET 2.0” tutorials are now available online at www.asp.net. These four tutorials illusrate how to add paging and sorting capabilities to the GridView and ObjectDataSource, showing how to page and sort naively, as well as how to use the more efficient custom paging technique. There's also a tutorial on creating a more customized sorting user interface.

Like the previous 23 tutorials, these four are each available in C# and VB versions, can be downloaded as PDFs, and have their complete source code available for download as a ZIP file.

Check 'em all out - http://www.asp.net/Learn/DataAccess

posted on Tuesday, August 15, 2006 5:57 PM

Feedback

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/17/2006 1:29 AM Patrick Oosterholt

Thank you! Those tutorials are great for me to learn how to properly use data in the new ASP.NET 2.0.

Will there be more in the future?

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/17/2006 9:00 AM Scott Mitchell

Patrick, there will be a total of (at least) 46 tutorials in total (I've actually got through #42 written). Perhaps Microsoft and I will work together in the future to add additional tutorials.

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/17/2006 3:05 PM nate

I'm am stumped on your VS2005 beginner tutorial included with the product. I am right clicking the project and adding a new item but the dataset item is not in the listing. I see only about a third of the items from the picture in the article.

nate@well.com

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/17/2006 6:51 PM Mark Fox

For lesson 25 – Efficient Paging I downloaded the file ASPNET_Data_Tutorial_25_VB.exe and than opened the project in VS 2005 Standard and ran PagingAndSorting/EfficientPaging.aspx. Clicking the PageLast >> button in GridView1’s pager gives a System.OverflowException in System.Web.UI.WebControls.GridView.CreateDataSourceSelectArguments().

Enabling the viewstate in GridView1 fixes this.

I have Microsoft .NET Framework and ASP.NET Version:2.0.50727.42 installed.

The same problem occurs with the C# version of the sample.

Does this occur for anyone else?

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/17/2006 8:21 PM Scott Mitchell

Mark, good catch! I can repro this problem fine. I can go directly to the last page and it works fine, but clicking Last gives me that overflow error. I'll definitely look into this tomorrow.

(Looks like others have had similar problems - http://forums.asp.net/thread/1280574.aspx)

Thanks again...

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/18/2006 9:04 AM Scott Mitchell

Ok, I found the problem. You are right, EnableViewState must be True to handle the "Last" page link when doing custom paging. The reason is because...

With custom paging, the page count value returned by the ObjectDataSource’s SelectCountMethod is stored in the GridView’s view state. Other GridView variables – the PageIndex, EditIndex, SelectedIndex, DataKeys collection, and so on – are stored in control state, which is persisted regardless of the value of the GridView’s EnableViewState property. Since the PageCount value is persisted across postbacks using view state, when using a paging interface that includes a link to take you to the last page, it is imperative that the GridView’s view state be enabled. (If your paging interface does not include a direct link to the last page, then you may disable view state.)

Clicking the last page link causes a postback and instructs the GridView to update its PageIndex property. If the last page link is clicked, the GridView assigns its PageIndex property to a value one less than its PageCount property. With view state disabled, the PageCount value is lost across postbacks and the PageIndex is assigned the maximum integer value instead. Next, the GridView attempts to determine the starting row index by multiplying the PageSize and PageCount properties. This results in an OverflowException since the product exceeds the maximum allowed integer size.


I'll go ahead and send in an update to the article/code to my editor at Microsoft. Thanks for the watchful eye, Mark!

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/25/2006 6:56 AM Steve Newbery

Scott - great stuff but I have a problem with the last one (27b) "Creating a Customized Sorting User Interface".

The problem is that when I have pager header or footer rows, those rows lose their colspan attribute, and the Next Last etc links are squeezed into a cell one column wide.

I have sent to your 4Guys email document with screenshots etc so you can see what I mean.

I also have a wish - which is that I can hide the column that has become the row heading - this to reduce the amount of data displayed. But when I adapt your code to hide it thus:

MyGridView.Columns(sortColumnIndex).Visible = False

It works, but the newly inserted row header disappears too. Can you see a way round this?

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 8/28/2006 5:47 AM Patrick Oosterholt

(repost because my previous try didnt show up)
Scott,

I have a problem while creating the dataset as explained in your first tutorial.

In my case i used my own tables and i selected to use stored procedures instead of SQL statements.

The problem is this:

One of my fields is an uniqueidentifier (GUID) and is nullable (field name is "UserID").

The creation of the update stored procedure fails with this error: "Operand type clash: uniqueidentifier is incompatible with tinyint
"

The line that causes the problem is this:
"(@IsNull_UserID = 1 AND ..."

Its understandable from SQL standpoint because @IsNull_UserID is an uniqueidentifier which can not be 1.

Problem is that the dataset created this line and this variable in the update stored procedure.

Is there a way arround this? (Other than writing the stored procedures myself ;)
)

Greetz,

Patrick

# re: The "Paging and Sorting" Tutorials from the "Working with Data in ASP.NET 2.0" Series are Now Online! 9/1/2006 6:07 PM Sabrina

On page 5 of the PDF for tutorial 2 (creaing a Business Logic Layer), there's a line missing in the UpdateProduct function. "product" never gets defined.

There needs to be a line like:

Dim product As Northwind.ProductsRow = products(0)

right? It's defined in the c# version, but not in the vb version.



Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles