【问题标题】:ObjectDataSource sets MaximumRowsParameterName= -1ObjectDataSource 设置 MaximumRowsParameterName= -1
【发布时间】:2013-04-02 23:54:58
【问题描述】:

我有一个 GridView 和一个 ObjectDataSource

<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>

一切似乎都很好。 但是当我在 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。 参数 RowStart 它发送正确的值(点击页面 1 发送 0,点击页面 2 发送 15...)

【问题讨论】:

  • 您必须将 SelectCountMethod 设置为您的 ObjectDataSource,我的回答是否解决了问题?
  • 好吧,我不再做它了(我没有源代码),但我确实想尝试一下,谢谢。

标签: asp.net vb.net gridview objectdatasource


【解决方案1】:

ObjectDataSource 控件的SelectCountMethod 属性设置为返回查询中记录总数的方法的名称。

您必须按以下方式实现数据源:

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

    MaximumRowsParameterName="NumRows"
    StartRowIndexParameterName="RowStart"

    EnablePaging="true">

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

</asp:ObjectDataSource>

或者您可以按照this URL 的示例进行操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多