当我尝试将ObjectDataSource,ListView和DataPager连接在一起时,正确的值不会传递给ObjectDataSource的select方法。始终为maximumRows
传递-1,为startRowIndex
传递0。
<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>
这是Address
命名空间中SuperApp.Business
类中的select方法:
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;
}
始终抛出第一个异常,因为maximumRows
始终为-1。我试过了:
我可能看不到明显的东西。有什么建议吗?
答案 0 :(得分:2)
是的,这应该是显而易见的。
您SelectCountMethod
上缺少ObjectDataSource
,因此不仅可以选择当前页面,还可以确定有多少个对象。
一个工作示例:
http://netpl.blogspot.com/2009/04/how-to-controll-aspnet-listview-page.html