GridView page changing doesn't work (Non SQL Source)

Discussion in 'ASP .Net' started by sck10, Dec 1, 2006.

  1. sck10

    sck10 Guest

    Hello,

    I have a GridView that I built to show the files in a directory. The
    problem that I am having is that when I click on the second page (2), the
    GridView disappears. Also, I can't sort by any of the columns.

    Below is the code that I am using. Any help would be appreciated.

    Thanks, sck10



    <asp:GridView ID="gvSearchList" runat="server"
    AllowPaging="True"
    AllowSorting="True"
    AutoGenerateSelectButton="False"
    AutoGenerateColumns="False"
    PageSize="15"
    style="width:70%"
    OnPageIndexChanging="gvSearchList_PageIndexChanging"
    OnSorting="gvSearchList_Sorting"
    OnSelectedIndexChanged="gvSearchList_SelectedIndexChanged">
    <Columns>
    <asp:BoundField DataField="Name"
    HeaderText="File Name"
    SortExpression="Name"
    HeaderStyle-VerticalAlign="Bottom"
    ItemStyle-HorizontalAlign="left"
    ItemStyle-Width="45%" />

    <asp:BoundField DataField="LastWriteTime"
    HeaderText="Last Write Time"
    SortExpression="LastWriteTime"
    HeaderStyle-VerticalAlign="Bottom"
    ItemStyle-HorizontalAlign="left"
    ItemStyle-Width="40%" />

    <asp:BoundField DataField="Length"
    HeaderText="File Size"
    ReadOnly="True"
    SortExpression="Length"
    HeaderStyle-VerticalAlign="Bottom"
    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="15%" />

    </Columns>
    </asp:GridView>



    protected void Search_Click(object Sender, CommandEventArgs Args)
    {
    this.DirectoryList(this.txtSearch.Text);
    }


    protected void DirectoryList(string DirectoryPath)
    {
    DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(str00));
    this.gvSearchList.DataSource = dirInfo.GetFiles("*.*");
    this.gvSearchList.DataBind();
    }


    protected void gvSearchList_SelectedIndexChanged(object Sender, EventArgs
    e)
    {

    }


    private string ConvertSortDirectionToSql(SortDirection sortDirection)
    {
    string newSortDirection = String.Empty;

    switch (sortDirection)
    {
    case SortDirection.Ascending:
    newSortDirection = "ASC";
    break;

    case SortDirection.Descending:
    newSortDirection = "DESC";
    break;
    }

    return newSortDirection;
    }


    protected void gvSearchList_PageIndexChanging(object sender,
    GridViewPageEventArgs e)
    {
    gvSearchList.PageIndex = e.NewPageIndex;
    gvSearchList.DataBind();
    this.gvSearchList.Visible = true;
    }


    protected void gvSearchList_Sorting(object sender, GridViewSortEventArgs
    e)
    {
    DataTable dataTable = gvSearchList.DataSource as DataTable;

    if (dataTable != null)
    {
    DataView dataView = new DataView(dataTable);
    dataView.Sort = e.SortExpression + " " +
    ConvertSortDirectionToSql(e.SortDirection);

    gvSearchList.DataSource = dataView;
    gvSearchList.DataBind();
    }
    }
    sck10, Dec 1, 2006
    #1
    1. Advertising

  2. Hi,

    I suggest you create a DataSource (with its DataView) to support pagination
    and sorting.

    Please take a look at following article:

    #Folder Contents DataSource Control - The Code Project - ASP.NET
    http://www.codeproject.com/useritems/FolderContentsDataSource.asp


    I think it's what you needed. Let me know if it's not the case.


    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Dec 4, 2006
    #2
    1. Advertising

  3. sck10

    sck10 Guest

    Thanks Walter.


    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi,
    >
    > I suggest you create a DataSource (with its DataView) to support
    > pagination
    > and sorting.
    >
    > Please take a look at following article:
    >
    > #Folder Contents DataSource Control - The Code Project - ASP.NET
    > http://www.codeproject.com/useritems/FolderContentsDataSource.asp
    >
    >
    > I think it's what you needed. Let me know if it's not the case.
    >
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications. If you are using Outlook Express, please make sure you clear the
    > check box "Tools/Options/Read: Get 300 headers at a time" to see your
    > reply
    > promptly.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    sck10, Dec 5, 2006
    #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. Replies:
    1
    Views:
    23,314
    Real Gagnon
    Oct 8, 2004
  2. Claus Atzenbeck
    Replies:
    1
    Views:
    1,061
    Claus Atzenbeck
    Nov 26, 2004
  3. sck10
    Replies:
    1
    Views:
    330
    sck10
    Dec 1, 2006
  4. sck10
    Replies:
    0
    Views:
    395
    sck10
    Dec 1, 2006
  5. Paul
    Replies:
    2
    Views:
    2,858
Loading...

Share This Page