views:

1068

answers:

2

Hi there,

Im using entity framework 1.0 and trying to feed out a Gridview with a objectdatasource that have access to my facade. The problem is, that it seems to be particulary difficult and haven't seen anything that realy do what i want it to do on the internet.

For those who know, a gridview feeded with an objectdatasource, it can't sort automaticaly then you must do it manually. It's not that bad. Where it becomes a nightmare, its when we add paging and filter settings to a gridview's datasource.

After many hours searching on the internet, i'm asking you, guys, if anyone knows a link that can explain me how to mix Pagging, Sorting and filtering for a gridview and an objectdatasource!

Thanks in advance and sorry for my english.

+1  A: 

FINALY! After 2 days of search, finaly found an alternative! Look this out!

http://www.unboxedsolutions.com/sean/archive/2005/12/28/818.aspx

Simon
+1  A: 

It may no longer be of interest for you, but I thought I post an answer nevertheless:

I am using Linq2Sql and a ObjectDataSource and it does Paging and Sorting very well.

I implemented a Class to be used as the ObjectDataSource. It has a Select and a Count method calling my business layer which uses Linq2SQL queries to retrieve data from the DB, should be similar with the EntityFramework. The select methods gets the first item index, page size and the sort expression as parameters automatically.

public List<EntityClass> Select(int startIndex, int pageSize, string sortBy) {}
public int Count() {}

In the ASPX, the DataSource is configured like this:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"  
     SelectMethod="Select" EnablePaging="true"
     StartRowIndexParameterName="startIndex" 
     MaximumRowsParameterName="pageSize"
     SortParameterName="sortBy" SelectCountMethod="Count" >   
</asp:ObjectDataSource>

The Select and the Count method use Linq queries to retrieve the data from the DB. I use the Skip(), Take() and Orderby() methods. For the OrderBy to accept a string sort expression I use DynamicLinq There is not much to code, Databinding, paging and Sorting are automatically working.

If you are interested I could post more details of my code.

PeterTheNiceGuy
Yea thats in this direction we've decided to go. But, I were interest to know if there a way to do to have something like an SQL datasource with what we do not have to do the job. My, dunno how to tell but my "head programmer" found out it Entity 4 in Studio 2010 LLBL Gen which is very powerfull, and sorting, paging and querying are quite more efficient and take a lot less ressrouces and it include powerfull sorting/paging methods who interact with database BEFORE returning all data. But thanks Peter! Maybe should I show some query when we're gonna have it full implemented!
Simon