PageCount

R

ruca

I'm validate some things in my dataGrid and if I delete all the records of
the last page of datagrid, it gives me an error saying: CurrentPageIndex
must be >=0 and <PageCount.
I want to know the PageCount after deleting the records, but this only
happens when I Bind DataGrid (and it's here that error ocurrs).

Can I know the number of pages of my DataGrig before doing DataBind to her?
How?
 
M

Michael Tkachev

double pagecount = Math.Ceiling((double)dvXXX.Count/(double)dgXXX.PageSize);

if (dgXXX.CurrentPageIndex >= pagecount && pagecount > 1.0)
dgXXX.CurrentPageIndex = (int)pagecount - 1;

if (dgXXX.CurrentPageIndex >= pagecount && pagecount == 1.0)
dgXXX.CurrentPageIndex = 0;

dgXXX.DataSource = dvXXX;

dgXXX.AllowPaging = (pagecount > 1);
dgXXX.Visible = (pagecount != 0);

dgXXX.DataBind();

Kind regards
Mikhail Tkachev.
..Net Developer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top