Click here to Skip to main content
15,890,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to bring data from database and bind the gridview each time when user clicks paging in the gridview,instead of bring the whole records and binding at once
Posted
Comments
Ashishmau 3-May-11 2:42am    
study paging concept of gridview first
Sandeep Mewara 3-May-11 2:49am    
tried anyhting at all?
Rajesh Anuhya 3-May-11 2:55am    
No Effort

There is a tip/trick describing how to page a gridview here: Showing a page of information at a time in a GridView[^]
 
Share this answer
 
Comments
BobJanova 3-May-11 6:55am    
Good link, answers the question
OriginalGriff 3-May-11 7:00am    
That's why I moved it to a tip/trick - I got fed up with posting the same stuff to different questions.
try this

use


C#
 // Allow Paging = true; in aspx page

 // Call Page index event  

OnPageIndexChanging="GridView1_PageIndexChanging"

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindGrid();
        }
 
Share this answer
 

There are many ways you can do this. But it has some restrictions on the data. You can use the following manner provided the below conditions.

Conditions:
The data needs to have a chronological ID field within it.

The process would be;

1. The first time you call the database, return top only top 5 (for example 5 rows) rows
2. Next you click a page number and query the database with the id number greater than the last number in the first record set. So for example, your first call (5 rows) returned the last row as ID 50, you search for the next top 5 records greater than 50 order by ID) and similarly, you do reverse if click on a page less than the present page (top 5 records less than 50 order by ID)

I hope you understand the logic behind getting data chunk by chunk on clicking of the pages in grid view instead of bringing the whole record set at once

You will need to know the predicted range of the ID field based on the query conditions for the whole data and then you can dynamically decide on fetching the data.

Let me know if you want to understand this more.

-Nayan
Coding is an earthly heaven
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900