Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Paging and sorting

    I have a datagrid that implements sorting. Once a click on a new page number,
    my sort gets lost.

    How can I combine sorting and paging?
    Arne Guest

  2. Similar Questions and Discussions

    1. Help with simple datagrid paging and sorting issue
      Please help! I have a simple web app that displays some search fields, posts back to itself onclick of the search button, and shows the results...
    2. Sorting and paging
      I have set up numerous datagrid controls and had a recurring problem with the sorting and paging features. They simply don't work and generate and...
    3. DataGrid - sorting/paging problem
      Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like...
    4. Sorting/Paging
      Brian, I've been saving the sort command to view state and then retrieving it on postback. -- S. Justin Gengo, MCP Web Developer /...
    5. Sorting with Paging
      Hi all When I tried to implement sorting on Datagrid that has paging is sorts only the displayed page (When I navigate to another page It looses...
  3. #2

    Default Re: Paging and sorting

    I had that problem and i think i fixed it (changed so many different
    things im not sure!) by adding using the ViewState. This is what works
    for me


    private void dgCusomter_PageIndexChanged(object source,
    System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
    {
    dgCusomter.CurrentPageIndex = e.NewPageIndex;
    ViewState["CurrentPageIndex"] = e.NewPageIndex;
    dgCusomter.DataBind();

    dgCusomter.SelectedIndex = -1;
    dgCusomter.EditItemIndex = -1;

    dgCusomter.DataBind();
    }


    private void dgCustomer_SortCommand(object source,
    System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
    {
    mySQLConnection sqlConn = new mySQLConnection();

    this.dgGarda.CurrentPageIndex = 0;
    ViewState["SortExprValue"] = e.SortExpression;

    sqlComm_Customer = new SqlCommand();

    sqlComm_Customer.Connection = sqlConn.GetConnection();
    sqlComm_Customer.CommandText = "SELECT * FROM Customer "+
    "ORDER BY "+e.SortExpression;
    sqlComm_Customer.CommandType = CommandType.Text;


    SqlDataAdapter daCustomer= new SqlDataAdapter(sqlComm_Customer);

    daCustomer.Fill(dsCustomer);
    dsCustomer.Tables[0].TableName = "Customer";
    BindData();



    }


    Hope it does the trick!,
    Steve

    steroche Guest

  4. #3

    Default Re: Paging and sorting

    Steroche,
    That is interesting. On sort, always take them to page one.
    Arne.

    "steroche" wrote:
    > I had that problem and i think i fixed it (changed so many different
    > things im not sure!) by adding using the ViewState. This is what works
    > for me
    >
    >
    > private void dgCusomter_PageIndexChanged(object source,
    > System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
    > {
    > dgCusomter.CurrentPageIndex = e.NewPageIndex;
    > ViewState["CurrentPageIndex"] = e.NewPageIndex;
    > dgCusomter.DataBind();
    >
    > dgCusomter.SelectedIndex = -1;
    > dgCusomter.EditItemIndex = -1;
    >
    > dgCusomter.DataBind();
    > }
    >
    >
    > private void dgCustomer_SortCommand(object source,
    > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
    > {
    > mySQLConnection sqlConn = new mySQLConnection();
    >
    > this.dgGarda.CurrentPageIndex = 0;
    > ViewState["SortExprValue"] = e.SortExpression;
    >
    > sqlComm_Customer = new SqlCommand();
    >
    > sqlComm_Customer.Connection = sqlConn.GetConnection();
    > sqlComm_Customer.CommandText = "SELECT * FROM Customer "+
    > "ORDER BY "+e.SortExpression;
    > sqlComm_Customer.CommandType = CommandType.Text;
    >
    >
    > SqlDataAdapter daCustomer= new SqlDataAdapter(sqlComm_Customer);
    >
    > daCustomer.Fill(dsCustomer);
    > dsCustomer.Tables[0].TableName = "Customer";
    > BindData();
    >
    >
    >
    > }
    >
    >
    > Hope it does the trick!,
    > Steve
    >
    >
    Arne Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139