Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone,

I have shown 10 numbers of data in a page. If 506 numbers of data are present in the database then i need my page counter display 51 pages, but it display only 50 pages.

Please any one can tell me, how can i solve this.

Thanks in advance

Here is my code:
C#
DataTable dt = article_list_class.getTotalArticles();
        totalrows = dt.Rows.Count;
        PAGEsize = 10;
        totalPageSize = totalrows / PAGEsize;
        if (totalPageSize % 10 == 0)
        {
            totalPageSize = Convert.ToInt32(totalPageSize);
        }
        else
        {
            totalPageSize = Convert.ToInt32(totalPageSize+1);
        }
Posted
Updated 27-Jun-11 1:57am
v2
Comments
Prerak Patel 27-Jun-11 7:29am    
Post your code, so that we can check the problem.
Tarun Mangukiya 27-Jun-11 7:38am    
ya post your code
RaviRanjanKr 27-Jun-11 7:55am    
Always be more specific while questioning. so Post your effort with your question :)

I have done this....

Here is the mistake:

C#
DataTable dt = article_list_class.getTotalArticles();
        totalrows = dt.Rows.Count;
        PAGEsize = 10;
        totalPageSize = totalrows / PAGEsize;
        if (totalPageSize % 10 == 0)
        {
            totalPageSize = Convert.ToInt32(totalPageSize);
        }
        else
        {
            totalPageSize = Convert.ToInt32(totalPageSize)+1;
        }
 
Share this answer
 
The problem is the integer division. It truncates, which is not what you want here. Try:

int totalrows = dt.Rows.Count;
int PAGEsize = 10;
int totalPageSize = (int)Math.Ceiling(totalrows * 1f / PAGEsize);


... or, if you want to do it with integer arithmetic only:

int totalrows = dt.Rows.Count;
int PAGEsize = 10;
int totalPageSize = (totalrows + PAGEsize - 1) / PAGEsize;
 
Share this answer
 
is your data is in gridview

common mistake
Instead of using Gridview.Rows.count you can use table.rows.count
here table is Gridview datasource table

thanks
Faisal
 
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