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

Discussion in 'ASP .Net' started by pittster, Dec 7, 2005.

  1. pittster

    pittster Guest


    I've bound a Gridview control to the GetFiles method

    Here is a code snippet:

    DirectoryInfo objDi = new

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

    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

    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

    pittster, Dec 7, 2005
    1. Advertisements

  2. pittster

    Guest 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.
    Guest, Dec 7, 2005
    1. Advertisements

  3. pittster

    pittster Guest

    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
    pittster, Dec 7, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.