views:

54

answers:

2

I haven't worked on the UI in some time. I thought that in ASP.NET 4.0, gridviews handle the paging automatically (if you set paging=true). Is this true, or do you still have to handle it in code?

+2  A: 

You will still need to handle the paging events, such as when the paging index changes. You have to handle PageIndexChanging, as well as YourGridView_Sorting as well. Just setting paging = true simply tells the project that you want the paging capability.

You still have to do the work of implementing the events such as when the page changes, or when you want a sort to occur.

From MSDN:

 The GridView control raises two events when it moves to a new page of
 data. The  PageIndexChanging event
 occurs before the GridView control
 performs the paging operation. The
 PageIndexChanged event occurs after
 the new page of data has been returned
 to the  GridView control.

Here's a link to how it can be implemented

If you love to watch videos, here is a good one: http://www.asp.net/data-access/tutorials#Paging and Sorting

JonH
A: 

Perhaps you are thinking of the new ListView and DataPager added in ASP.Net 3.5.

The new ListView is an update to the old DataList and Repeater controls, displaying multiple records and providing functionality like GridView, but allowing for a more flexible layout through the use of templates.

The new DataPager is a free-standing paging interface. It renders a paging UI - Next, Previous, First, and Last buttons - and is tied to a data web control. It only works with controls that implement the IPageableItemContainer interface, which (currently) is only ListView.

According to this enthusiastic article in MSDN magazine, "The ListView can literally replace all other data-binding controls in ASP.NET."

Now that you have a better idea what you're looking for, you can probably find plenty of help about ListView and DataPager. For starters, this 4GuysFromRolla series should be a big help: Using ASP.NET 3.5's ListView and DataPager Controls: The Ultimate DataPager Interface

DOK