Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a doubt on grid-view.. i have a database with 1 lack records.. suppose if i want to retrieve 1 lack database records at a time the database performance will be decreasing.. i want to retrieve the records based on the page size.. suppose my page size is 100 if i press first page button call first 100 records only from database..and i press 2nd button call 101-200 records only..can any one help for this problem.. thank you
Posted
Updated 29-Jul-12 19:45pm
v3

its nothing but paging in gridview

Add Gridview


XML
<asp:gridview id="DgTest" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
            Width="100%" AllowSorting="True" OnRowCommand="DgTest_RowCommand" 
            OnRowDataBound="DgTest_RowDataBound" AllowPaging="True" 
            onpageindexchanging="DgTest_PageIndexChanging" CaptionAlign="Right"> </asp:gridview>


Create PageIndexChanging event as

C#
protected void DgTest_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            DgTest.PageIndex = e.NewPageIndex;
            Populate();
        } 


C#
private void Populate()
        {
            //Code To get datasource to Databind
        }

Dont forget to set property Pagesize=100
 
Share this answer
 
Comments
srikanthgvs 30-Jul-12 1:56am    
ok but its enough for 100 or 200 records.. but i have 1 lakh records if i want to take 1 lakh records at a time... the database performenace will be not faster
[no name] 30-Jul-12 2:23am    
ok then think another option like scrollable Gridview , each time u scroll down just add more records, like facebook posts
Use Paging and Sorting concept of GridView


Read the following links for concepts:
http://msdn.microsoft.com/en-us/library/aa479347.aspx[^]

http://www.c-sharpcorner.com/uploadfile/rohatash/gridview-paging-sample-in-asp-net/[^]

set pagesize property to 100
 
Share this answer
 
There are so-many efficient ways to query n records from the data base.

SQL
SELECT TOP numberofrecordsyouwanttotake
    [yourColumns...]
FROM tableName
WHERE yourIDColumn NOT IN (
    SELECT TOP numberofrecordsyouwanttoskip
        yourIDColumn
    FROM tableName
    ORDER BY yourOrderColumn
)
ORDER BY yourOrderColumn



Thanks!!!
 
Share this answer
 
hiii,


one solution is that
datasource will be get
by
using
below sample Query

SQL
select * from
   (select Row_Number() over (order by employee_id) as RowIndex, * from employee) as Sub
   Where Sub.RowIndex >= @record_start and Sub.RowIndex < @record_end 



where pass parameter

@record_start=(GridPageIndex-1)*GridpageSize
@record_end=GridPageIndex*GridpageSize


populated dataset bind to gridview will improve your speed
 
Share this answer
 

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