15,117,549 members
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 2: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 :)

## Solution 2

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;
}```

## Solution 3

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;```

## Solution 1

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

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

Top Experts
Last 24hrsThis month
 Richard Deeming 140 OriginalGriff 130 CHill60 110 phil.o 55 Richard MacCutchan 45
 Richard Deeming 140 CHill60 110 OriginalGriff 95 phil.o 55 Richard MacCutchan 40

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