In this article we will see how to fetch records from a database in chunks for page scrolling.
Introduction
In this article we will create a web application in which we get data from the in a scrollable page using jQuery and get simple pagination on page scrolling.
Create Stored Procedure
USE [Northwind]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--This procedure will get data from Customer Table using parameters StartIndex and EndIndex
CREATE PROC [dbo].[usp_GetCustomersByPaging]
@StartIndex INT
,@EndIndex INT
AS
BEGIN
SELECT Row,CompanyName, ContactName,ContactTitle FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY CustomerID DESC) AS Row,
CompanyName, ContactName,ContactTitle
FROM Customers
) AS Customers
WHERE Row BETWEEN @StartIndex AND @EndIndex
END
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Pagination on scroll</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
var startInd = parseInt($("#hdfStartIndex").val());
var endInd = parseInt($("#hdfEndIndex").val())
$("#hdfStartIndex").val(startInd + 10);
$("#hdfEndIndex").val(endInd + 10);
bindData();
}
});
});
function bindData() {
var startInd = $("#hdfStartIndex").val();
var endInd = $("#hdfEndIndex").val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "scrollpaging.aspx/BindDatatable",
data: "{startIndex: " + startInd + "," + "endIndex:" + endInd + "}",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.d.length; i++) {
$("#gvDetails").append("<tr><td><img src='images.jpg' alt='image' width='100px' height='100px'/> </td> <td>" + data.d[i].CompanyName + "</td><td>" + data.d[i].ContactName + "</td><td>" + data.d[i].ContactTitle + "</td></tr>");
}
},
error: function (result) {
alert("Error");
}
});
}
</script>
<style type="text/css">
table, th, td
{
border: 1px solid black;
border-collapse: collapse;

bashiruddin SheikhPosted Jan 13, 2016, 7:40 AM
Please sagged ME......>
bashiruddin SheikhPosted Jan 13, 2016, 7:39 AM
Please reply me my datatable 300 records 1sd show 50 and Scroll after 50 records ..........
bashiruddin SheikhPosted Jan 13, 2016, 7:38 AM
Please tell me Datatable to data Paging on Page Scroll in jQuery as.net???