Objectdatasource and Gridview: sorting, paging, filtering

Im using an entity framework 1.0 and trying to pass a gridview to an object data source that has access to my facade. The problem is that it seems to be especially complex and does not see anything that really does what I want it to do on the Internet.

For those who know, gridview filed using objectdatasource, it cannot sort automatically, then you have to do it manually. It's not so bad. Where this becomes a nightmare is when we add paging and filter settings to the gridview data source.

After many hours of searching the Internet, I ask you guys if anyone knows a link that can explain to me how to mix Pagging , Sort and Filter for gridview and objectdatasource!

Thanks in advance and sorry for my English.

+4
source share
4 answers

Finaly! After 2 days of searching, the final alternative is found! Check it out!

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

+1
source

Perhaps this is not of interest to you, but I thought that I would send an answer anyway:

I use Linq2Sql and an ObjectDataSource object, and it performs paging and sorting very well.

I implemented a class that will be used as an ObjectDataSource object. It has a Select and Count method, calling my business layer, which uses Linq2SQL queries to retrieve data from a database, should look like EntityFramework. Selection methods automatically get the first index, page size, and sort expression.

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

In ASPX, the DataSource is configured as follows:

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

The Select and Count method uses Linq queries to retrieve data from the database. I use the Skip (), Take (), and Orderby () methods . For OrderBy, to use the string sort expression, I use DynamicLinq . Code coding, data processing, paging and sorting do not work.

If you're interested, I can post more details about my code.

+5
source

This explanation is pretty good and simple: GridView ObjectDataSource LINQ Partitioning and Sorting .

+1
source

I know this is an old question, but here's how I deal with it. Add an ObjectDataSource object to my aspx page:

 <asp:ObjectDataSource ID="myDataSource" runat="server" SelectMethod="GetSearchResults" EnablePaging="true" StartRowIndexParameterName="startIndex" MaximumRowsParameterName="pageSize" SortParameterName="sortBy" SelectCountMethod="GetSearchCount" > </asp:ObjectDataSource> 

Please note that the type is missing? I set this in code on my Page_Load page

 myDataSource.TypeName = this.GetType().AssemblyQualifiedName; 

Then I use static methods on one page (in the same class) to update the gridview:

 public static int GetSearchCount() { return _RowCount;//set elsewhere in code - this is the total number of rows for the query } public static DataTable GetSearchResults(string sortBy, int pageSize, int startIndex) { //Code to dynamically generate SQL statements based on supplied parameters //then return a datatable containing only the data to be shown in the gridview } 
0
source

All Articles