2012-07-30 3 views
1

ObjectDataSource, ListView 및 DataPager를 연결하려고하면 올바른 값이 ObjectDataSource의 select 메서드에 전달되지 않습니다. -1은 항상 maximumRows으로 전달되고 startRowIndex에는 0이 전달됩니다.ObjectDataSource, ListView 및 DataPager를 어떻게 연결합니까?

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 :

<asp:DataPager runat="server" ID="Address_DataPager" PageSize="50" PagedControlID="Address_ListView" > 
    <Fields> 
     <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true" 
      FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|" 
      NextPageText=" &gt; " PreviousPageText=" &lt; " /> 
    </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> 

이것은 SuperApp.Business 네임 스페이스의 Address 클래스의 선택 방법은 다음과 같다. 나는 시도했다 :

  • DataPager를 LayoutTemplate으로 옮긴다.
  • DataPager를 LayoutTemplate으로 이동하고 PagedControlID 값을 제거하십시오.
  • DefaultValue 값을 모든 종류의 것으로 변경합니다.
  • 매개 변수에서 DefaultValue 제거.
  • 매개 변수에서 유형 제거.
  • SelectParameters를 완전히 제거하십시오.

아마도 내가 볼 수없는 것은 분명합니다. 어떤 제안?

답변