Paging and sorting

A

Arne

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?
 
S

steroche

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top