CSLADataSource FormView Paging

CSLADataSource FormView Paging

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


Aver posted on Tuesday, August 19, 2008

Hi Guys,
   Started working with CSLADataSource today and the FormView controls. I want to use the paging of the formview control. I copied the paging example from ProjectList.aspx  but it does not in the FormView. I have made sure to enable paging on both the FormView and the CSLADataSource. When I use numeric paging it shows the proper number of objects. Changing the page however has no effect on the databound to the formview. Is there anything I need to do to tell the datasource what object to load?

A Code Example would be:

<csla:CslaDataSource ID="MyDataSource" runat="server" TypeName="MyObjectLibrary.Library.MyObject, MyObjectLibrary.Library"
        TypeSupportsPaging="True" TypeSupportsSorting="True" OnSelectObject="MyDataSource_SelectObject" />
 <asp:FormView ID="FormView1" runat="server" DataSourceID="MyDataSource"
       AllowPaging="True" DataKeyNames="ObjectID" PageIndex="0">
        <ItemTemplate>
        <label>Property 1</label><input type="text" value='<%# Eval("Field1") %>' />
        </ItemTemplate>
</asp:FormView>

Aver replied on Wednesday, August 20, 2008

Ok

   So I have found a solution that will work however, it does not seem to be ideal. What I have done is the following.

In the FromView's PageIndexChanging event I change the pageindex on the form. Then in the CSLADataSource SelectObject event I select the index matching pageindex from my collection. This works but it also removes the proper row count from the formview. So before when I was setting the e.BusinessObject to my List the Form View would show the number of objects in the list. I understand that now by binding directly to an object of the list I am going to lose this functionality.

I guess now what I am wondering is there anything I need to do to the CslaDataSource or my BusinessList object to tell it what index to use? If I check e.statrowindex (In the SelectObject event) it matches the FormView's PageIndex but the bound fields are never updated.

I think it is either how I am setting the e.BusinessObject on the SelectEvent ? Or CslaDataSource wont work with FormView Paging.

RockfordLhotka replied on Wednesday, August 20, 2008

Have you read the CSLA .NET Version 2.1 Handbook? In that book I walk through the various options you can use to do paging with CslaDataSource - at least with the GridView control.

Aver replied on Thursday, August 21, 2008

Thanks for the suggestion Rocky. I bought the book last night and everything makes sense now.

Copyright (c) Marimer LLC