Gridview Sort doesn't sort!

Gridview Sort doesn't sort!

Old forum URL: forums.lhotka.net/forums/t/739.aspx


david.wendelken posted on Thursday, July 27, 2006

I'm at the point where I'm starting to use my business object library by web pages.

I'm using a GridView control for the first time and everything seemed really easy and straightforward until I started to test the sorting.  It doesn't sort.

I have the AllowSorting="True" defined in the gridview tag, and I have SortExpression="thePropertyName" defined in the bound field tags.

Any clues?  I'm using caching per the ResourceList.aspx page example if that is mucking things up.

 

david.wendelken replied on Thursday, July 27, 2006

The documentation in the book I'm using says what I did above is all that's needed...

I created a gridview_sorting and gridview_sorted event handlers.  Debugging shows that gridview_sorting is receiving the correct sort criteria...

I tried issuing a databind  and also removing the cache and then databinding, but no change in behavior.

 

david.wendelken replied on Thursday, July 27, 2006

My colleague just came in and said, "Did you search for an answer?"

Duh. 

Obviously, she metabolizes caffiene faster than I do.  Or she's smarter than me... :(

See this thread.

http://forums.lhotka.net/forums/thread/1550.aspx

HardPressed replied on Sunday, May 25, 2008

This took me several hours to figure out and it seems pretty stupid but all you have to do is add

a OnGridView_Sorting Event to fire .... my code looks like this after setting a datasource

try

{

this.gvProject.DataBind();

}

catch

{

//No rows , so alternate report sent

NoActualData = true;

gvProject.Visible = false;

}

if (this.gvProject.Rows.Count > 0)

try

{

String sort = this.gvProject.SortExpression;

this.gvProject.Sort("PID", SortDirection.Descending);

}

catch (Exception ex)

{

ex.ToString();

}

protected void gvProject_Sorting(object sender, GridViewSortEventArgs e)

{

if(e.SortExpression == "WBS" && this.gvProject.SortDirection == SortDirection.Ascending )

{

this.gvProject.Sort("WBS", SortDirection.Descending);

}

}

Copyright (c) Marimer LLC