Adding paging to a Gridview Control bound to DirectoryInfo.GetFiles()

P

pittster

Hi,

I've bound a Gridview control to the GetFiles method

Here is a code snippet:

DirectoryInfo objDi = new
DirectoryInfo(Server.MapPath("./somepath"));

FileInfo[] arrFileInfo = objDi.GetFiles();
GridView2.DataSource = arrFileInfo;
GridView2.DataBind();

The GridView has 1 defined BoundField - "Name"

I've enabled pageing, but when I click on a page number I get the
following message:

The GridView 'GridView2' fired event PageIndexChanging which wasn't
handled

I understand that I need to handle the event.

However I don't know how to increment the index of the datasource to
the appropriate index to show the next page's values (ie Show the next
10 values)

Any help would be appreciated. Please show example code if you have
any.

Thanks.
 
G

Guest

If I understand correctly, I think, If you use the following statement in
your pageindexchanged event handler. it should work.

GridView2.CurrentPageIndex = e.NewPageIndex;

where e is the DataGridPageChangedEventArgs.
 
P

pittster

Thank you Kiran it helped me in the right direction.

The only thing that was missing was to rebind the data to the datagrid.
Once I did that it appeared to work.
But you have to do the Index change before the rebind.

So the code would be:
GridView2.PageIndex = e.NewPageIndex;
//Datasource Code here - probably a "bindit()" function
GridView2.DataBind();
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top