Groups | Blog | Home
all groups > asp.net datagrid control > august 2005 >

asp.net datagrid control : Paging and sorting


Arne
8/22/2005 8:40:23 AM
I have a datagrid that implements sorting. Once a click on a new page number,
my sort gets lost.

steroche
8/23/2005 9:20:08 PM
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
8/24/2005 2:53:09 AM
Steroche,
That is interesting. On sort, always take them to page one.
Arne.

[quoted text, click to view]
AddThis Social Bookmark Button