When I try to connect together an ObjectDataSource, a ListView and a DataPager, the correct values are not passed to the select method of the ObjectDataSource. -1 is always passed for maximumRows
and 0 is passed for startRowIndex
.
<asp:DataPager runat="server" ID="Address_DataPager" PageSize="50" PagedControlID="Address_ListView" >
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true"
FirstPageText="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</Fields>
</asp:DataPager>
<asp:ListView ID="Address_ListView" runat="server"
DataSourceID="Address_DataSource" DataKeyNames="AddressId" >
<LayoutTemplate>
<table class="resultsGrid">
<tr class="gridRow">
<th scope="col">Address</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="gridRow">
<td>
<asp:Label ID="Address_Label" runat="server" Text='<%# Eval("Address") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="Address_DataSource" runat="server" TypeName="SuperApp.Business.Address"
SelectMethod="SelectAddress" EnablePaging="True"
MaximumRowsParameterName="maximumRows"
StartRowIndexParameterName="startRowIndex" >
<SelectParameters>
<asp:Parameter Name="maximumRows" DefaultValue="10" Type="Int32" />
<asp:Parameter Name="startRowIndex" DefaultValue="5" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
This is the select method in the Address
class in the SuperApp.Business
namespace:
System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public DataTable SelectAddress(int maximumRows, int startRowIndex)
{
if (maximumRows < 1) throw new ArgumentOutOfRangeException("maximumRows", "Maximum rows should be greater than zero.");
if (startRowIndex < 0) throw new ArgumentOutOfRangeException("startRowIndex", "Start row index should be greater or equal to zero.");
if (startRowIndex >= maximumRows) throw new ArgumentOutOfRangeException("startRowIndex", "Start row index should be less than the maximum rows.");
// Would do something interesting here.
return null;
}
The first exception is always thrown, as maximumRows
is always -1. I have tried:
- Moving the DataPager into the LayoutTemplate.
- Moving the DataPager into the LayoutTemplate and removing the PagedControlID value.
- Changing the DefaultValue values to all sorts of things.
- Removing the DefaultValues from the Parameters.
- Removing the Type from the Parameters.
- Removing the SelectParameters completely.
It is probably something obvious that I just can't see. Any suggestions?