|
-
July 5th, 2005, 12:34 PM
#1
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?
-
July 5th, 2005, 01:48 PM
#2
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.
-
July 6th, 2005, 10:49 AM
#3
Re: datagrid sort event fires twice
Here's the page load:
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
...not much help.
-
July 6th, 2005, 01:16 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|