2013-04-02 37 views
0

我有一個GridView和一個ObjectDataSourceObjectDataSource控件設置MaximumRowsParameterName = -1

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="myType" SelectMethod="FindByName" 
    MaximumRowsParameterName="NumRows" StartRowIndexParameterName="RowStart" EnablePaging="true"> 
    <SelectParameters> 
     <asp:Parameter Name="namex" Type="String" Direction="Input" DefaultValue="" /> 
     <asp:Parameter Name="RowStart" Type="Int32" Direction="Input" DefaultValue="0" /> 
     <asp:Parameter Name="NumRows" Type="Int32" Direction="Input" DefaultValue="15"/> 
    </SelectParameters> 

Everyting似乎很好地工作。 但是,當我改變頁面上的GridView和ObjectDataSource調用方法它發送參數NumRows = -1(StartRowIndexParameterName =「NumRows」)。 如果我叫ObjectDataSource.Select()把它發送numRows行= 0

即使我設定的值的參數numRows行

Protected Sub ObjectDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource.Selecting 
     e.InputParameters("NumRows") = 15 
End Sub 

的ObjectDataSource仍然發送-1或0 To參數RowStart它發送右擊值(點擊頁面1發送0,點擊頁面2發送15 ...)

+0

您必須將SelectCountMethod設置爲您的ObjectDataSource,我的答案是否解決了問題? –

+0

嗯,我不再工作了(我沒有源代碼),但我想嘗試它,謝謝。 – Logar314159

回答

0

SelectCountMethod屬性ObjectDataSource控件設置爲返回查詢記錄總數的方法的名稱。

您必須實現您的數據源,如下所示:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    TypeName="myType" 
    SelectMethod="FindByName" 
    SelectCountMethod="GetMyTypeCount" 

    MaximumRowsParameterName="NumRows" 
    StartRowIndexParameterName="RowStart" 

    EnablePaging="true"> 

    <%--TODO : ...--%> 

</asp:ObjectDataSource> 

,或者你可以按照this URL例子。