Home > ASP.NET > CodeFluent Entities and ASP.NET Web Forms Binding: Paging Data

CodeFluent Entities and ASP.NET Web Forms Binding: Paging Data


Here’s the second post of the series, and this one shows how to set-up your ASP.NET ObjectDataSource and GridView controls to page your data. Just like in the first post, we’ll use the same model containing a single Contact entity, and which uses two producers the SQL Server Producer to generate the persistence layer and the Business Object Model Producer to generate my .NET classes.

This time, we need to add a little more attributes to our ObjectDataSource declaration:

<asp:ObjectDataSource runat="server" ID="PagedContactDataSource" SelectMethod="PageLoadAll"
    TypeName="ContactAdmin.ContactCollection" DataObjectTypeName="ContactAdmin.Contact"
    EnablePaging="true" StartRowIndexParameterName="pageIndex" MaximumRowsParameterName="pageSize">
    <SelectParameters>
        <asp:Parameter Name="pageIndex" Type="Int32" DefaultValue="0" />
        <asp:Parameter Name="pageSize" Type="Int32" DefaultValue="100" />
        <cfw:PageOptionsParameter Name="pageOptions" DefaultPageSize="100" />
    </SelectParameters>
</asp:ObjectDataSource>

You can see above that we’re using a PageOptionsParameter control. As the paged methods generated by CodeFluent Entities take a PageOptions class in addition to the pageIndex and pageSize parameters, the CodeFluent Web Runtime (CodeFluent.Runtime.Web.dll) provides the appropriate ASP.NET server control so you can use those methods declaratively. You’ll then need to register the control in your page like this:

<%@ Register Assembly="CodeFluent.Runtime.Web" Namespace="CodeFluent.Runtime.Web.UI.WebControls" TagPrefix="cfw" %>

Or you can also do it for your entire web site by doing it in the web.config:

<system.web>
  <pages>
      <controls>
	(...)
	<add tagPrefix="cfw" namespace="CodeFluent.Runtime.Web.UI.WebControls" assembly="CodeFluent.Runtime.Web"/>
      </controls>
  </pages>
</system.web>

Note: you don’t have to use the “cfw” prefix, anyone will do.

Now that our data source is set, let’s configure our GridView to use our PagedContractDataSource and display pages of 4 records:

<asp:GridView runat="server" DataSourceID="PagedContactDataSource" AutoGenerateColumns="False" 
    AllowPaging="True" PageSize="4"> 
    <Columns> 
        <asp:BoundField HeaderText="Id" DataField="Id" /> 
        <asp:BoundField HeaderText="First Name" DataField="FirstName" /> 
        <asp:BoundField HeaderText="Last Name" DataField="LastName" /> 
    </Columns> 
</asp:GridView>

Et voilà, paging is up and running, our 6 records are now split into two pages:

image image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s