Wednesday, July 28, 2010

Sorting and paging using gridview in asp.net when binding with a datable

protected void AssignedQualInbox_Sorting(object sender, GridViewSortEventArgs e)


{

//Retrieve the table from the session object.

DataTable dataTable = Session["AssignedQualInbox"] as DataTable;



if (dataTable != null)

{

// Check the DataTable itself for the previous sort expression and sort the data

if (dataTable.DefaultView.Sort.ToString() == (e.SortExpression.ToString() + " ASC"))

{

dataTable.DefaultView.Sort = e.SortExpression + " DESC";

}

else // Handles cases where the previous sort expression was the current expression descending, another expression, or none at all.

{

dataTable.DefaultView.Sort = e.SortExpression + " ASC";

}



AssignedQualInbox.DataSource = Session["AssignedQualInbox"];

AssignedQualInbox.DataBind();

}



}



protected void AssignedQualInbox_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

AssignedQualInbox.PageIndex = e.NewPageIndex;

AssignedQualInbox.DataBind();

}

No comments:

Post a Comment