This article shows how to load on-demand data into a Webgrid on a scroll using ASP.Net and jQuery AJAX.

You have certainly visited various Ecommerce sites where you can see the list of products as you scroll the page looking for more products. New products are loaded when scrolliing down. In a similar way I am showing you how to do that with webgrid.

asp MVC jquery ajax logo

Procedure

Database

Table

The following is a snapshot of the Customer table.

sql query

Stored Procedure

Creating Project

Model

Controller part

Let us start this part by adding a new controller with the name “MemberController” then you will see a similar view in your project.

controller

View part

Script
  1. In the following script I have bound a Scroll to a Div tag. Load the Webgrid rows when the DIV is scrolled.

    Webgrid Rows

  2. In this part of the script I have just appended an image at the bottom of the webgrid (show loader). And below that there is an ajax method where I am posting a “pageindex” to jsonresult as Input. And the URL that we use in this is: "/Member/GetCustomers".

    web grid

    For success I have written another function called Onsuccess.

  3. In this last function below with the name Onsuccess I am removing the loader because I want to add rows below it.

Using the Response that I am getting from the Jsonresult we need to add rows to the grid for that I had use the .append function and inside that I created a table rows and columns using <tr> <td> and inside that added data that we need to display using “ + dataval.MiddleName + ”.

Finally assigning a data value from the database to JSON pagecount variable and hiding the loader.

function

Now we have completed everything, just run the application and check it.

You can download the entire code and check for any issues.

Final output

File uploaded successfully!show grid data.jpg