What is paging in asp.net




















The PagedList. Mvc package installs a paging helper that displays the paging buttons. In the Package Manager Console window, make sure the Package source is nuget. This code adds a page parameter, a current sort order parameter, and a current filter parameter to the method signature:. The first time the page is displayed, or if the user hasn't clicked a paging or sorting link, all the parameters are null. If a paging link is clicked, the page variable contains the page number to display.

A ViewBag property provides the view with the current sort order, because this must be included in the paging links in order to keep the sort order the same while paging:. Another property, ViewBag.

CurrentFilter , provides the view with the current filter string. This value must be included in the paging links in order to maintain the filter settings during paging, and it must be restored to the text box when the page is redisplayed.

If the search string is changed during paging, the page has to be reset to 1, because the new filter can result in different data to display. The search string is changed when a value is entered in the text box and the submit button is pressed.

In that case, the searchString parameter is not null. At the end of the method, the ToPagedList extension method on the students IQueryable object converts the student query to a single page of students in a collection type that supports paging. That single page of students is then passed to the view:. The ToPagedList method takes a page number. The two question marks represent the null-coalescing operator.

The null-coalescing operator defines a default value for a nullable type; the expression page?? The changes are highlighted. The model statement at the top of the page specifies that the view now gets a PagedList object instead of a List object. The using statement for PagedList. Mvc gives access to the MVC helper for the paging buttons. The code uses an overload of BeginForm that allows it to specify FormMethod. The text box is initialized with the current search string so when you click a new page you can see the current search string.

The column header links use the query string to pass the current search string to the controller so that the user can sort within filter results:. If there are no pages to display, "Page 0 of 0" is shown.

We can use a simple stored procedure or SQL statement to fetch the total number of records from database i. Now we need to come up with some algorithm for fetching only required number of rows. The same can be implemented in various ways. We can implement the same depending on our application requirements. Perhaps the easiest case is to fetch the data a single table which has an auto incremental primary key. The SQL statement is shown below.

If we don't have any auto incremental primary key then we fetch data from the table after joining the table with a temporary table which has an auto incremental primary key.

The SQL statements are shown below. Populate this temporary table using data from the table from which we need to fetch our data Employee in our case. Now we can join the temp table and Employee table to fetch the required records as shown below. There are some other ways also to fetch the required number of records from database i.

To use above approach, we need to supply the Primary Key of Previous Page when we are inquiring for a next page and vice versa. Above SQL statement will return 10 records starting from 11 to Once we are able to fetch the required number of records, the rest is very similar to what we have done in case of default paging i.

Richard Deeming May Nitesh Kejriwal May Nitesh Kejriwal Apr Member Feb Humayun Kabir Mamun Sep Nitesh Kejriwal Sep Wombaticus 9-Sep Nitesh Kejriwal 9-Sep Go to top.

Layout: fixed fluid. First Prev Next. Simple and easy to use MarcusCole Nov Cheers and thank you. Query regarding paging concept Member Nov Member These hyperlinks will be used by user to navigate through the pages.

Let me start with Stored Procedure. It comes with the demo project that you may have downloaded. Take a look at the screenshot below:. You may want to change the Procedure name, but don't forget to change the procedure name in the host page too. As you know, a stored procedure is a business specific object, and its parameter names are strongly dependent on the names of your business objects. So, you should customize some of its variables. To make the world easy for myself and of course for you, I colorized the sections we have a special focus on them.

To modify the stored procedure to fit into your business, do the following. We will start from the bottom to top:. Take a look at the figure below:. Let's see how we can use it and how it can play its role in our paging system. You can customize the Pager control via its properties.



0コメント

  • 1000 / 1000