Database Paging and Sorting with CSLA Part 3 - The presentation layer

by Cliff 8. September 2007

This is the final part on how to implement database paging with a custom CSLA business class and SQL Server 2005.  In this post I will demonstrate how to call the business object from part two from the applications presentation layer.  This approach will place minimal code in the presentation layer and allows for clean seperation and the ability to write automated tests against the intended behavior.

 I used a DataGrid and CSLADataSource to present the data from the list class:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="CslaDataSourceInfoList"

DataKeyNames="Id" OnRowDeleted="GridView1_RowDeleted" Width="100%" PageSize="10"

AllowPaging="True" AllowSorting="true" EmptyDataText="No Records Available."

PagerSettings-Mode="NumericFirstLast ">

<Columns>

<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id"

Visible="False" />

<asp:HyperLinkField HeaderText="Subject" SortExpression="Subject" DataNavigateUrlFormatString="InfoEdit.aspx?id={0}"

DataNavigateUrlFields="Id" DataTextField="Subject" ItemStyle-Width="300" />

<asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True"

SortExpression="CategoryName" ItemStyle-Width="75"/>

<asp:BoundField DataField="Description" HeaderText="Description" ReadOnly="True"

SortExpression="Description" ItemStyle-Width="200"/>

<asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center">

<ItemTemplate>

<asp:Button ID="btnDelete" CommandName="Delete" runat="server" Text="Delete"

OnClientClick="showConfirm(this); return false;" />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<csla:CslaDataSource ID="CslaDataSourceInfoList" runat="server" TypeAssemblyName=""

TypeName="InfoTracker.InfoListItem, InfoTracker" TypeSupportsPaging="True" TypeSupportsSorting="False"

OnSelectObject="CslaDataSourceInfoList_SelectObject" OnDeleteObject="CslaDataSourceInfoList_DeleteObject">

</csla:CslaDataSource>

In the code behind, I used the SelectObject event handler to retrieve the business object and specify the paging information.  Finally in the GetInfoList method I call into the business class to get the data:

protected void CslaDataSourceInfoList_SelectObject(object sender, Csla.Web.SelectObjectArgs e)

{

InfoList infoList = GetInfoList(GridView1.PageIndex, GridView1.PageSize, GetSort(GridView1.SortExpression, GridView1.SortDirection.ToString()),tbSearch.Text);

lblTotalRecords.Text = infoList.TotalRecordCount.ToString();

e.BusinessObject = infoList;

}

private InfoTracker.InfoList GetInfoList(int index, int pageSize, string sort, string searchString)

{

return InfoTracker.InfoList.GetInfoList(index, pageSize, sort, searchString);

}

Comments

April 30. 2008 11:56

Gravatar

I have implemented the code just as you described in part 2 and the "TotalRecordCount" doesnt show up as a property of my class in part 3

TJ us

April 30. 2008 13:00

Gravatar

I needed to add a public property to the business object to expose the TotalRecordCount:

//Property that can be used in UI to display total number of records
public int TotalRecordCount
{
get { return _totalRowCount; }
}

You should now be able to see this property once you add it to your class.

Cliff us

September 4. 2009 02:13

pingback

Pingback from beyondnet.codesol.info

Video – Reunión ALT .NET Café 29 De Agosto « BeyondNet

beyondnet.codesol.info

August 25. 2010 05:45

pingback

Pingback from alabamaweddings.interactiveinfonet.info

Alabama weddings - Alabama wedding - Alabama photographer wedding

alabamaweddings.interactiveinfonet.info

September 13. 2010 16:48

pingback

Pingback from jobsinhouston.interactiveinfonet.info

Houston art jobs - Houston jobs - Jobs in houston

jobsinhouston.interactiveinfonet.info

Comments are closed

Cliff Gray's Info

Cliff Gray
Developer/Founder GrayTechnology.com.

E-mail me Send mail

Authors

Calendar

<<  October 2021  >>
MoTuWeThFrSaSu
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Blogroll

Download BlogEngine.NET

Download at CodePlex

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2021

Subscribe