I have a logical problem. Assume I have a table that includes 1000 rows. When I want to display the data in a repeater, I first bind CollectionPager 1000 rows, so CollectionPager knows how many pages there will be, and after that, CollectionPager will be my repeaters datasource.
If I index my table using Row_Number() property and select 10 records per time, and multiply it with my page_number, since its selecting 10 records only, its performance will be good. But at this time my pager does not know how many total records are there and so It does not make paging.
In the other hand I do not want to select all 1000 rows?
What do you offer me?
Thank you.
I would suggest to have one and the very first trip to database to just find out the count of total records that you will going to get, you can store it in the viewstate or hidden fields for further page post backs.
Then you can fetch 10 records per database trip and so you will always have
10 records from the database + Total records count that you can use for your pager
In this way your pager will always know the total number of records and hence will perform the paging accordingly
Related
Right now my website(ASP.NET) has a database where it pulls data from, and the more data enter the longer the page. I am wondering how I can make it so for example once it pulls ten items from database it starts a new page and puts ten more items on the next. Basically like how http://fmylife.com does it.
Thanks
You should take a look att the DataPager Control.
To create a solution that works in the long run, you need to let the paging selection end up in your sql where clause, so that you only retreive the amount of records that you have specified in the PageSize property of the DataPager Control each time you round trip to the database. Otherwise it will lose it's performace when the records in the database increases.
I am trying to populate records on a gridview depending on the result of two linq methods:
GetRecords(string SearchCriteria, int skip, int take)
which provides me the ammount of rows i´m going to show into the gridview, and
CountRecords(string SearchCriteria)
Which provides me with the total count of the records.
First I get the number of records by using the CountRecords method, and then I calculate the number of pages to make the user know how many pages the gridview has, but the property gridview.PageCount is read only. How can i set the ammount of pages the gridview is going to have, without getting all the records (they're about 300000, so i cannot afford this option)?
Set virtual count. Set AllowCustomPaging to true.
http://msdn.microsoft.com/en-us/library/zxdbyxtc.aspx
I have a gridview which was working fine with a small dataset in development. In production it has to bind to thousands of records, which is making it slower to load. Is there a way to improve performance, like retrieving the data during gridview pageindex changing?
Also chances are you only want to bind it once. So you should (if not already):
if(!IsPostback)
{
DatabindGridLogicHere();
}
This way your GridView will only have to hit the db the first time to get the data.
First and formost turn off ViewState.
You should tell your datasource to take less records and then enable paging in your grid and datasource.
You can enable "AllowPaging" property to true in your GridView and give a page size say 10. Then Write your data retrieval logic to return a batch of data instead of the whole set of data at once.
When you write the SQL query make sure to order it by an ID.
Thus if the page index is 1 you can take the first batch of data by passing page index of 1 and the page size of 10.
Logic will be;
SELECT [RequiredFields]
FROM [YourDataSource]
WHERE (Id>=((PageIndex-1)*pageSize) AND Id<(PageSize*pageIndex)) ORDER BY Id
In the first page it will return first set of entries of those Ids starting from 0 to 9. In the second page it returns entries of those Ids starting from 10 to 19 assuming the pageSize is 10. You can change the page size and the query logic as you wish.
But if sorting is enable then this will not produce accurate results.
I'm coding a report page. In this page, there are two date fields for user to filter the date and the GridView is filled depending on these dates in the CodeBehind (When user click the button view). Now I want to implement a paging/sorting feature for this GridView. I've researched and see there are default paging for GridView which is not very efficient (my report table may have thousands of records) and custom paging but this requires using ObjectDataSource (which I don't use). Thus anyone can recommend me some approaches that are best used in this situation? Some tutorials will be gladly appreciated :)
Thanks,
Assuming you have the records stored in a database, I would get the record count and use that number for paging. Then I'd query for the ones I want to see on each page.
string.Format(#"
SELECT TOP {0} * FROM Records WHERE pkId NOT IN (
SELECT TOP {1} pkId FROM Records ORDER BY pkId
) ORDER BY pkId;",
upperBoundary,
lowerBoundary
);
Where upperBoundary would be lowerBoundary + itemsPerPage, for example. Using MSSQL, we don't have the luxury of MySQL's LIMIT feature, but this does the same.
Narrowing down on dates, would be something like
SELECT * FROM Records WHERE Date > earlyDate AND Date <= lateDate
This is the most effecient way in my oppinion, cause it causes little traffic and if you cache the record count, you won't have many queries flying around either.
how can I create a query in order to select some records every time user wanna to display them into a gridview. I don't want to select all entire records from my data source. What I exactly want is to simulate pagination by query.
Thank you
Have a look at
Efficient Paging for GridView