Paging and sorting

Discussion in 'ASP .Net Datagrid Control' started by Arne, Aug 22, 2005.

  1. Arne

    Arne Guest

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

  2. Arne

    steroche Guest

    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.DataGridPageChangedEventArgs 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.DataGridSortCommandEventArgs 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, Aug 24, 2005
    #2
    1. Advertising

  3. Arne

    Arne Guest

    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.DataGridPageChangedEventArgs 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.DataGridSortCommandEventArgs 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, Aug 24, 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. Mo
    Replies:
    1
    Views:
    4,240
    FFlannery
    Jan 30, 2004
  2. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    DataSet paging vs Datareader paging

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    10,865
    Scott Allen
    Oct 8, 2004
  3. wh1974
    Replies:
    0
    Views:
    2,490
    wh1974
    Jan 12, 2005
  4. Red
    Replies:
    1
    Views:
    767
  5. anil reddy
    Replies:
    0
    Views:
    958
    anil reddy
    Feb 11, 2009
Loading...

Share This Page