Datagrid & paging

B

ByB

Hello,

I have a problem in C# with a datagrid i use with paging.

With the paging I can display 10 items in one page.
Those items can be deleted separately.
When i delete one of them, i update the datatable used as datasource
and I redo a DataBind() for the datagrid.

If i have 11 items to display, the 11th item is displayed in the 2nd
page. But if i delete it, the application crashes and I get the
information that CurrentPageIndex is not valid (since I have not 2
pages anymore but 1)

I tried to set the CurrentPageIndex to 1 before I do the databind() but
i get the same error.

Is there a way to correct this ?

thanks.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You should make the current page = 0 no 1.

Take into account that this is not the best solution, what happen if you
have 21 instead of 11?
The solution is store the currentpage, delete the items fmor the db and
rebind the grid, check if the currentpage is still a valid page if so set it
or in the other case set it to the max page count possible using PageCount

cheers,
 
B

ByB

OK, thank you very much for your answer ! :)

Ignacio Machin ( .NET/ C# MVP ) a émis l'idée suivante :
 

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

Top