Solution
I came across your question while seeking an answer to the exact same situation. I found a solution elsewhere ... not exactly what you were looking for you do have to create handlers but here's some nice generic ones...
<asp:GridView ID="gridView" OnPageIndexChanging="gridView_PageIndexChanging"
OnSorting="gridView_Sorting" runat="server" />
private string ConvertSortDirectionToSql(SortDirection sortDireciton)
{
string m_SortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
m_SortDirection = "ASC";
break;
case SortDirection.Descending:
m_SortDirection = "DESC";
break;
}
return m_SortDirection
}
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridView.PageIndex = e.NewPageIndex;
gridView.DataBind();
}
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable m_DataTable = gridView.DataSource as DataTable;
if (m_DataTable != null)
{
DataView m_DataView = new DataView(m_DataTable);
m_DataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
gridView.DataSource = m_DataView;
gridView.DataBind();
}
}
I had to tweak this up a bit, as gridview datasource was null ... I went back through my custom SQL build and did DataBind() again and it works !
Good luck.