setting TotalRowCount for CustomDataSource.DataSource when paging

Topics: Web Client Software Factory
Nov 17, 2006 at 8:15 AM
Hello,

When I enable paging on a GridView I would like to assign to the CustomDataSource.Datasource property only the list of objects for the current page index. Therefore I also need to be able to tell the CustomDataSource what the TotalRowCount is so that the GridView can correctly render the paging controls. I will handle the PagingIndexChanging event of the GridView to retrieve and assign the list of objects for the new page index to the DataSource property. Can functionality be added to the CustomDataSource class to set the TotalRowCount and for the DataSource to hold only the list of objects for the current page index?

cheers,

Remco
Nov 17, 2006 at 2:38 PM
I agree...
Developer
Dec 5, 2006 at 5:49 PM
Thanks for the feedback.

We are currently adding server-side paging capabilities to the control. To perform server-side paging, you will have to perform the following steps:

1. Set a property of the control named UsingServerPaging to true. This will indicate to the control that it doesn't have to perform paging automatically.
2. In the webpage, handle the Selecting event. This event is fired by the control before passing any object to the data-bound control:

----
// View.aspx.cs
protected void CustomersDataSource_Selecting(object sender, ObjectContainerDataSourceSelectingEventArgs e)
{
_presenter.OnSelecting(e.Arguments.StartRowIndex, e.Arguments.MaximumRows, e.Arguments.SortExpression);
}
----

3. When handling the event, retrieve the items you need, and set the items and the total row count in the view:

----
// Presenter.cs
public void OnSelecting(int startRowIndex, int maximumRows, string sortExpression)
{
View.Customers = _controller.GetCustomers(startRowIndex, maximumRows, sortExpression);
View.TotalCustomersCount = _controller.CustomersTotalCount;
}
----

This is the code for the Customers and TotalCustomersCount properties in the view that simply forward the values to the control:

----
public IList<Customer> Customers
{
set { CustomersDataSource.DataSource = value;
}

public int TotalCustomersCount
{
set { CustomersDataSource.TotalRowCount = value; }
}
----

There will also exist a property named UsingServerSorting that indicates to the control that it doesn't have to sort the items, so you can sort it manually.

Cheers
Mariano Szklanny
http://staff.southworks.net/mariano
Dec 5, 2006 at 7:32 PM
This looks perfect. Any ETA for when this will be testable in a build?
Developer
Dec 6, 2006 at 2:49 AM
The new version of the control will be included in next drop.

Cheers,
Mariano Szklanny
http://staff.southworks.net/mariano