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

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

  1. Guest

    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.
    , Dec 7, 2005
    #1
    1. Advertising

  2. RE: Adding paging to a Gridview Control bound to DirectoryInfo.GetFile

    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.

    --
    Thanks
    Kiran Kumar Pinjala


    "" wrote:

    > 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.
    >
    >
    =?Utf-8?B?S2lyYW4gS3VtYXIgUGluamFsYQ==?=, Dec 7, 2005
    #2
    1. Advertising

  3. Guest

    Re: Adding paging to a Gridview Control bound to DirectoryInfo.GetFile

    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();
    , Dec 7, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Cox [Microsoft MVP]

    Re: DirectoryInfo.GetFiles(Mask) finding too many files!

    Ken Cox [Microsoft MVP], Jan 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    811
    Ken Cox [Microsoft MVP]
    Jan 26, 2005
  2. Mario Krsnic
    Replies:
    0
    Views:
    366
    Mario Krsnic
    Jun 23, 2006
  3. =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?=

    Directory.GetFiles() / DirectoryInfo.GetFiles() on a remote server

    =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?=, Mar 22, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    1,924
    BradM
    Mar 24, 2007
  4. Replies:
    1
    Views:
    330
    Ben Rush
    Apr 3, 2007
  5. Steve Kershaw
    Replies:
    3
    Views:
    2,507
    David R. Longnecker
    Jun 29, 2007
Loading...

Share This Page