We're binding our GridView to a list object we get back from our CodeGen class, this is how I got ours to work:
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
// Now switch the sortexpression
string sortExpression = e.SortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
}
else
{
GridViewSortDirection = SortDirection.Ascending;
}
List<sss.DataTier.Interact.Podcast> podcastList = gvPodcasts.DataSource as List<sss.DataTier.Interact.Podcast>;
sss.DataTier.Interact.Podcast.Comparer podcastComparer = new PodcastBase.Comparer(PodcastBase.PodcastColumn.Title);
podcastList.Sort(podcastComparer);
if (e.SortDirection == GridViewSortDirection)
{
podcastList.Reverse();
}
gvPodcasts.DataSource = podcastList;
gvPodcasts.DataBind();
}
C# Web Developer
When is Microsoft going to get rid of VB.NET!