datagrid sort event fires twice

The datagrid sort event fires twice with the result of this being the order does not change. The asc/desc order switches on the first event and then switches on the second time which actually sets it back to the original order. The basic code pieces are:

protected int BindResultsToDatagrid(string sortExpression)
{
searchResultsDataSet =(DataSet)Session{"searchResultsDataSet"];
if (sortExpression.Length > 0)
{
searchResultsDataSet.Tables[0].DefaultView.Sort = sortExpression;

Session["searchResultsDataSet"] = searchResultsDataSet;
}
searchResults.DataSource = null;
searchResults.DataBind();

searchResults.DataSource = searchResultsDataSet.Tables[0].DefaultView;
searchResults.DataBind();
return searchResultsDataSet.Tables[0].DefaultView.Count;
}

protected void searchResults_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
string sortExpression = (string)Session["sortExp"];
string sortDirection = (string)Session["sortDir"];

if (sortExpression != e.SortExpression)
{
sortExpression = e.SortExpression;
sortDirection = "asc";
}
else
{
if (sortDirection == "asc")
sortDirection = "desc";
else
sortDirection = "asc";
}

Session["sortExp"] = sortExpression;
Session["sortDir"] = sortDirection;
BindSearchResultsToGrid(sortExpression + " " + sortDirection);
}

I actually copied this code from the net, and I'm surprised it's out there and doesn't work. Can anyone help?
[1645 byte] By [mcourier] at [2007-11-19 10:47:58]
# 1 Re: datagrid sort event fires twice
can you show me the Page Load event?there might be something happening there that's causing the sort to fire twice.
cafedreamz at 2007-11-9 1:49:29 >
# 2 Re: datagrid sort event fires twice
Here's the page load:

private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}

...not much help.
mcourier at 2007-11-9 1:50:40 >
# 3 Re: datagrid sort event fires twice
I got it figured out! I had OnSortCommand="searchResults_SortCommand" on the ascx page for the datagrid and this.searchResults.SortCommand += new DataGridSortCommandEventHandler(searchResults_SortCommand); in the code behind.
mcourier at 2007-11-9 1:51:33 >