title: Gridview sorting challenge when moving from Winforms to ASP.NET 2.0 Webforms
body: <p>I have a problem with Gridview sorting that is similar to others but I'm binding to a collection object as opposed to a data table.</p>
  
  <p>The existing business rules and data access layers of an application follow the pattern of having an object and, if you need a collection of objects of that type, to have another class inheriting CollectionBase and implementing IBindingList.</p>
  
  <p>For desktop applications, it was easy to databind a gridview to one of these objects and there weren't any problems with turning on column sorting.  Everything was 'in state' in the desktop app's presentation layer.</p>
  
  <p>Now that code is being moved to a new web application (ASP.NET 2.0, VB codebehind pages).</p>
  
  <p>I've played around with what I had to do to only have certain columns of the collection show up in the gridview and the gridview looked pretty good.  When I turned on 'allow sorting', that's when the problems showed up.</p>
  
  <p>I'm getting the error about not having a .Sorting method, etc.  In researching this, I found all sorts of solutions that were easily implemented with dataviews <em>if</em> my source was a data table.  But it's not - it's a collection.  I tried to "cheap shot" a datasource by converting the collection to an XML memory stream and them trying to .ReadXML back into a dataset but that didn't work [Root element is missing error was as far as I got in the dataset.ReadXml(ioTemp) where ioTemp was the System.IO.MemoryStream used in the xml serializer].</p>
  
  <p>Because of the old desktop apps, I've never had to worry about sorting a collection since the gridview handled it once it was loaded.  In fact, it's a 'standard' that the collection's .SortProperty, .SortDirection and .ApplySort all through NotSupportedExceptions (I inherited this code from programmers long gone).</p>
  
  <p>Is there an easy way to convert the collection to a data table or a way to sort the collection without having to go back to the database each time?  Object Data Sources won't work becuase of the intricate rules in how the objects are built - the wizards in VS2005 just can't handle what we need to do (grabbing data from several tables conditionally to make an object).</p>
  
  <p>Thanks in advance.</p>