Sorting And Paging Without Using DS

Posts   
 
    
bargizey
User
Posts: 10
Joined: 18-Dec-2007
# Posted on: 18-Dec-2007 16:45:18   

Hi all,

First of all, we are using LLBLGEN at our proffesional sw company for about 2 years and it is a life saver product definitely. We are so glad to be its customer.

My question is,

I am using LLBLGEN Data Sources generally, but at one project one of our developers preferred to handle bindings manually, without using DSs. And as i review the code, I saw his code for binding like that:

    TestCollection testCollection = new TestCollection();

    IPredicateExpression filter = new PredicateExpression();

    filter.AddWithAnd(TestFields.LanguageId == new Guid(LanguageCriteriaDropDownList.SelectedValue));

    testCollection.GetMulti(filter);

                            //SORT EXPRESSION IS PASSED FROM THE DATAGRID'S 
                            //SORTING EVENT ACCORDING TO THE HEADER CLICKED 
    if (sortExpression.Length != 0)
    {
        testCollection.Sort(sortExpression, (System.ComponentModel.ListSortDirection) sortDirection, null);
    }

    TestGridView.DataSource = testCollection;
    TestGridView.DataBind();

As you can see, once it is retrieving the whole data, then it is sorting and paging through the whole collection. That is ofcourse a performance problem. And if we have used a DS, it would have surely retrieve only needed data (fully, i hope it simple_smile )

Now, we have a paging enabled datagridview with some headers for sorting. And we do not have any datasets... How can we handle sorting and paging?

PS: I do not prefer a lame code like this:

if (sortExpression == "Field1") { testCollection.GetMulti(filter, 0, sortExpression1); }else if (sortExpression == "Field2") { testCollection.GetMulti(filter, 0, sortExpression2); }

Thank you for your concern...

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 18-Dec-2007 18:05:34   

i ran into the same scenario on a project. where i needed to bind manually to the gridview. I also needed db paging to increase preformance.

In the end I created a simple Datasource control which took an enumerable and virtual item count in the constructor. then I bound the gridivew to my custom data source.

EntityCollection<MyEntity> data = //fetch data;
int vic = //Get Total Number of Records from DB

gridview.DataSource = new MyPagingDataSource(data, vic);
gridview.DataBind();

if this isn't an option you may need to create a custom paging template for the gridview. and manually add paging by fetching the total record count. calculating the number of pages.

<asp:gridview ...>
     <pagingtemplate>
            //add majic here to create paging
     </pagingtemplate>
</asp:gridview>

//gridview databound event
protected void GridView_DataBound(object sender, EventArgs e)
{
     int numberOfRecords = //fetch total record count
     int numberOfPages = numberOfRecords  / gridview.PageSize;
     //logic to create custom paging template
}
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Dec-2007 09:28:56   

Check the following thread for sorting based on a filed string name: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10562

And for paging there is an overload of the GetMulti() method that accepts a PageSize and PageNumber parameters

bargizey
User
Posts: 10
Joined: 18-Dec-2007
# Posted on: 19-Dec-2007 14:06:38   

Oh, thank you for the responses. I got both of my questions' answers.

Greetings from Turkey simple_smile