ReadOnlyListBase vs. SortedBindingList Sorting Columns ASP:GridView

ReadOnlyListBase vs. SortedBindingList Sorting Columns ASP:GridView

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


jstevens posted on Thursday, December 27, 2007

I have been working with CSLA for several months now with good success (currently using 3.03 version with WCF).  I have read all of the CSLA books and combed through the forums, but can anyone clarify whether you can apply column sorting on a ASP:GridView using ReadOnlyListBase?  I am creating a page similar to ProjectTracker ResourceList.aspx  for a mortgage company where I only need to sort by clicking on the header names of the columns of Id, Name, Date, LoanAmount.  From what I have read, if I use SortedBindingList, I will have to pull the entire collection back.  Am I misunderstanding this?  Can anyone suggest the best method for accomplishing this?   

JoeFallon1 replied on Friday, December 28, 2007

A ReadOnly Collection cannot sort itself in CSLA 2.0 and higher. IN 1.x there was some code added by the community to allow this but Rocky decided that "Views" on the collection was a better way to go and the community has followed that path.

So you should retrieve your ROC from the DB and then create a SortedBindingList based on the ROC. Then the datasource of your grid is set to the SortedList.

There is no need to "pull the entire collection back" just because you are sorting. If you plan to show the user different data then you need to re-fetch that data and then re-sort it. If you happen to have "all the data" then you can just re-sort it.

Joe

 

jstevens replied on Friday, December 28, 2007

Thanx Joe!  So if I understand you correctly, I can use SortedBindingList to only pull back the 4 fields I mentioned in the post above?  Will I have to programmatically sort the collection for Ascending/Descending, or will the automatic features of the asp:gridview allowsorting="True" simply work?  Also, I am seeing under the CSLA datasource: typesupportssorting="True" - does this only apply to SortedBindingList collections?  Finally, have you worked with ObjectListView and what are your thoughts on it?

JoeFallon1 replied on Friday, December 28, 2007

1. You use a ROC (Read Only Collection) to pull data from the DB. It could have an inner Info class with whatever fields you want. Even just those 4.

2. Once you have the ROC in hand you can then use a SortedBindingList.

3. I have not used a gridview with a csladtasource so I cannot tell you how to make them work together. I programmatically sort my BOs.

4. I have used the ObjectListView extensively. In fact I avoided SortedBindingList and FilteredBindingList because I wanted to use a single control to do both. And the ObjectListView supports sorting on multiple properties which was critical. SoretdBindingList only sorts on one property. I like ObjectListView a lot. But there are some quirks to be aware of: When casting the Item back to your class you have to add the .Object property to then end of the expression. The actual item is nested one level deeper than you might expect. It was also very slow in a couple of situations. I think I had to replace it with a FilteredBindingList to get it to work well enough. I think the author (Brian Criswell)was going to tweak the code but he has been very busy moving to LA from England and starting a new job.

Joe

 

 

jstevens replied on Monday, December 31, 2007

Joe,

I got the ObjectListView to work over the weekend - thanx for your all your help, your code worked perfectly with Brian's ObjectListView class.  I am posting back on the public forum so everyone can see the final solution I came up with.  Turns out that no matter what BO I used, the header sorting capabilities of the ASP:GridView will not work without a ridiculous amount of code (SQL queries, reflection, arraylist, etc.). The wizard capabilities of the control are great, but the control doesn’t expose the necessary events needed to bind the data for web based gridview control sorting.  So, I tried a couple of third party gridviews and found that Infragistics2.WebUI.UltraWebGrid version 7.1 worked out of the box.  Should have tried this first – I could have saved two days worth of coding…

Copyright (c) Marimer LLC