protected void PendingWorkGridView_OnSorting(object sender, GridViewSortEventArgs e)
{
// For some reason the SortDirection property is not getting set automatically so set manually
e.SortDirection = e.SortExpression.IndexOf(" DESC") > 0 ? SortDirection.Descending : SortDirection.Ascending;
List<MyWorklistItem> pendingWorkItems = (List<MyWorklistItem>) Session["MyWorkItems"];
pendingWorkItems.Sort(new MyWorklistItemComparer(e.SortBLOCKED EXPRESSION;
// Update SortExpression for the column, toggling between ASC and DESC
foreach (DataControlField column in PendingWorkGridView.Columns)
{
if (column.SortExpression == e.SortExpression)
{
column.SortExpression = e.SortDirection == SortDirection.Ascending
? e.SortExpression + " DESC"
: e.SortExpression.Replace(" DESC", string.Empty);
break;
}
}
PendingWorkGridView.DataSource = pendingWorkItems;
PendingWorkGridView.DataBind();
}
protected void PendingWorkGridView_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
PendingWorkGridView.PageIndex = e.NewPageIndex;
PendingWorkGridView.DataBind();
}
Read the complete post at http://www.dotnetmafia.com/Home/tabid/37/EntryID/145/Default.aspx