Using GridView paging with BusinessListBase-inherited object.

Using GridView paging with BusinessListBase-inherited object.

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


MarkHildreth posted on Wednesday, April 18, 2007

Hi all.

Still trucking through the early stages of learning the framework, I've encountered this problem:

I've created a class named (notoriously..) "Bug" which inherits from BusinessBase. It has a child object which is a class called "BugComments" that inherits from BusinessListBase, each object in the list being also a BusinessBase ("BugComment"). I've attached this child object to a grid view on the page where the parent class is the main business object, and am trying to do paging on the grid view (at grid-view level, no worries about performance at this stage).

I was able to easily accomplish this with another list on another page that inherited from ReadOnlyListBase. I'm trying to do things similarly, however, I'm running into the following problem with BugComments...

The paging always seems to have the correct amount of pages (if the page size is three and I have nine "comments", there are three pages). However, all of the pages, except for the last one, will always have the first X items, where X is the size of the page. So, if the page size is four, then pages one, two and three will have the first three items listed (where two and three should have their own unique items). When I hit the final page, I get ALL of the items listed, even if it's more than the paging should handle.

I switched the data source to read straight from the database through a different adapter and it worked as it should.

The SelectObject function for the CslaDataSource...

    protected void bugCommentsDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
    {
        Bugz.Bug obj = GetBug();
        e.BusinessObject = obj.BugComments;
    }


GetBug()...

    private Bugz.Bug GetBug()
    {
        object businessObject = Session["currentObject"];
        if (businessObject == null || !(businessObject is Bugz.Bug))
        {
            try
            {
                string idString = Request.QueryString["id"];
                if (String.IsNullOrEmpty(idString))
                {
                    businessObject = Bugz.Bug.NewBug();
                }
                else
                {
                    businessObject = Bugz.Bug.GetBug(Convert.ToInt32(idString));
                }
            }
            catch (System.Security.SecurityException)
            {
                Response.Redirect("BugList.aspx");
            }
            catch (Csla.DataPortalException)
            {
                Response.Redirect("BugList.aspx");
            }
        }

        return (Bugz.Bug)businessObject;
    }

Thinking it might've been something that I did with the GetBug and persisting the object in Session, I went to just getting it every time from the db...

    protected void bugCommentsDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
    {
        // Bugz.Bug obj = GetBug();
        //e.BusinessObject = obj.BugComments;
        e.BusinessObject = Bugz.Bug.GetBug(Convert.ToInt32(Request.QueryString["id"])).BugComments;
    }

Same incorrect results.

Any ideas?

cslasoup replied on Thursday, June 09, 2011

Did you ever get this resolved?  I am currently having the same issue.  This is the first result I've come across in my search for a solution so I will keep looking.

[UPDATE] I figured out the issue for my case.  Since my object doesn't directly support paging or sorting, the TypeSupportsPaging and TypeSupportsSorting properties on the CSLADataSource object should have been set to False but instead I had them set to True.  Changing them to False allowed the GridView to handle the paging automatically.

If your object DOES support paging and sorting, then you should set those properties to True so that ASP.NET defers those actions to your business object.  

Source: P. 635 Expert VB 2008 Business Objects.

Hope this helps someone else out.

Copyright (c) Marimer LLC