Friday, March 26, 2010

Gridview SortExpression and SortDirection not being set

I was doing a lot of manual binding to a Gridview and tried to implement a sort. This is no easy task without using some type of ObjectDataSource, but I made it to a point where I had it working except the actual SortExpression and SortDirection didn't seem to be set.

A quick google search turned out others complaining of the same problem and complaining that SortExpression and SortDirection were Get only properties. A quick hit of System.Reflection let me set those values with:


typeof(GridView).GetField("_sortExpression", BindingFlags.NonPublicBindingFlags.Instance).SetValue(this.gvSearchResults, e.SortExpression);

typeof(GridView).GetField("_sortDirection", BindingFlags.NonPublic BindingFlags.Instance).SetValue(this.gvSearchResults, e.SortDirection);


Doing this turned up the real problem. My DataSource was not considered Sortable and setting those fields caused the Gridview to attempt to sort it, thus throwing an exception.

The only solution I've come up with in this case is to manage the SortExpression and SortDirection in Viewstate myself and display images/do datasource sorting with my own code.

Thursday, March 11, 2010

Google Chrome Frame IE Add-On Changes User Agent Sometimes While Not In Use

I was having session key troubles recently and finally tracked down the problem...The Google Chrome Frame Add-On for IE 8 changes the user agent under certain conditions; most notably the first page load or if you refresh the page by hitting Enter on the url bar instead of the Refresh icon.

In short, it either needs to inject this crap every time or only when I am using a Chrome Frame.

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; InfoPath.2; .NET CLR 3.0.30729)

Changed to this

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; InfoPath.2; .NET CLR 3.0.30729) chromeframe/5.0.342.0


Needless to say, I uninstalled this crap, but not before it ate up hours of my time tracking it down. I've lost a little faith in Google's goodness today along with those hours of time wasted.