Hello,
I am binding gridview on page load, it has many records, so it takes so much time to load data. How to load it faster, also, it has pagination to it.
Maybe "Load More" option would work, but how to manage it with Pagination and what need to change in coding part.
Thanks in advance !

Jayraj ChhayaRank #304 · 8.2K reputationPosted Nov 12, 2024, 1:03 AM EST
Hi Sushant Torankar,
To improve the loading speed of your GridView while maintaining pagination, consider implementing asynchronous data loading techniques. Instead of binding all records at once, you can load a subset of data initially and then fetch additional records as needed.
Here’s a basic approach using the "Load More" functionality:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(0, 10); // Load first 10 records } } private void BindGrid(int startIndex, int pageSize) { // Fetch data from the database var data = GetData(startIndex, pageSize); GridView1.DataSource = data; GridView1.DataBind(); } // AJAX method to load more records [WebMethod] public static List LoadMore(int startIndex, int pageSize) { return GetData(startIndex, pageSize); }Performance Improvement Tips
Sushant TorankarRank #3,026 · 476 reputationPosted Nov 15, 2024, 3:35 PM EST
I am using Oracle databse
Sangeetha SRank #212 · 11.4K reputationPosted Nov 12, 2024, 6:58 AM EST
To Load More records in GridView with pagination try this,
ASP.NET
AJAX call
let currentPage = 1; \/\/ Initialize current page function loadMore() { currentPage++; $.ajax({ url: 'YourPage.aspx\/GetData', \/\/ Update with your page and method type: 'POST', contentType: 'application\/json; charset=utf-8', data: JSON.stringify({ page: currentPage }), success: function (data) { \/\/ Append new records to the GridView or update your GridView $('#GridView1').append(data.d); }, error: function (error) { console.error(\"Error loading more data:\", error); } }); }Server side c#
[WebMethod] public static List GetData(int page) { int pageSize = 10; using (SqlConnection conn = new SqlConnection("YourConnectionString")) { conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM YourTable ORDER BY YourColumn OFFSET @Offset ROWS FETCH NEXT @PageSize ROWS ONLY", conn); cmd.Parameters.AddWithValue("@Offset", (page - 1) * pageSize); cmd.Parameters.AddWithValue("@PageSize", pageSize); SqlDataReader reader = cmd.ExecuteReader(); List dataList = new List(); while (reader.Read()) { YourDataType data = new YourDataType { }; dataList.Add(data); } return dataList; } }Benjamin Gabriel10 reputationPosted Nov 20, 2024, 2:14 AM EST
To implement a "Load More" functionality for your GridView in C#, modify your data query to load a subset of records using SQL's OFFSET and FETCH NEXT or ROW_NUMBER() for pagination. In your C# backend, create a method to fetch paginated data based on the current page number and page size, and bind the first page of data on page load. Add a "Load More" button below the GridView, and in its Click event, fetch the next set of records, append them to the existing GridView data, and update the page number in the ViewState. This approach reduces the initial load time and progressively loads more data when the user clicks "Load More."
It worked for here essaybucket.com for a project, hope it will work for you as well.