【问题标题】:Data Source is not supported server side pagination数据源不支持服务器端分页
【发布时间】:2014-08-20 13:53:34
【问题描述】:

我正在从事的项目有数十万条来自数据库的记录。我必须在 DevExpress 网格中显示这个。 网格的默认行为是一次加载所有记录,并在客户端应用分页。 我遇到的问题是页面在加载时需要大量时间。为了阻止这种情况,我将在 devExpress 网格中使用服务器端分页。但我收到错误:“The data source does not support server-side data paging

我的网格是“gvList”,我将其属性设置为:

gvList.DataSourceForceStandardPaging = True

然后

Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim da As SqlDataAdapter
Dim dbConn As New SqlConnection(conStr)
cmd.CommandType = CommandType.Text
cmd.CommandText = strSQL     'contains SQL string
cmd.Connection = dbConn      'contains connection object
da = New SqlDataAdapter(cmd)
da.Fill(ds, tbl)
gvList.DataSource = ds
gvList.DataBind()

谁能告诉我哪里出错了?

谢谢.. 安朱姆·达米尔

【问题讨论】:

  • @Magnus Burton,在链接中,您发送的 LINQ 查询正在使用,而我正在使用简单查询。
  • 当然,但它遵循相同的原则。使用您的查询,但添加 Limit 0,10 以显示前 10 行。 Limit 10,10 显示第 11 到 20 行
  • 好的,我在查询中添加了 Limit 0,10,但最终出现错误。你能举个例子告诉我吗?
  • 你能告诉我你的查询吗?

标签: asp.net vb.net visual-studio devexpress


【解决方案1】:

ASPxGridView 支持三种不同的数据绑定模式:

1) 当所有数据都被获取到 Web 服务器并由 ASPxGridView 本身处理时的通用绑定; 2)服务器端排序和分页。此功能通过激活 ASPxGridView 的DataSourceForceStandardPaging 属性来开启;在这种情况下,您需要使用 ObjectDataSource,因为 SQLDataSource 不支持服务器端分页。 3) 真实服务器模式,几乎与网格数据相关的计算(如分组、汇总)都在数据库服务器上实现。上面的链接包含有关此模式的一些有用信息。

因此,解决此问题的最简单方法是使用我的第二个选项。第三个选项更强大,但需要一些额外的工作。

【讨论】:

  • 感谢您的回答,但是是 DataSet ObjectDataSource 还是 SQLDataSource ?
  • DataSet 既不是 ObjectDataSource 也不是 SQLDataSource。这些是在 ASP.NET 中特别使用的不同本质。如果您需要在 ASPxGridView 中实现分页 - 使用我在答案中提供的选项之一。
【解决方案2】:

使用Custom Pagination 方法。

因此,您应该将网格与数据源相关联。它可以是对象数据源或其他。 在数据源中,应将一些参数发送到包含选择和计数方法的类。

一个例子:

网络表单

<asp:ObjectDataSource ID="ds"
    EnablePaging="True"
    TypeName="Namespace.to.Service"
    runat="server"
    SelectMethod="FindAll"
    SelectCountMethod="FindAllCount"
    StartRowIndexParameterName="startRow">
    <SelectParameters>
        <asp:Parameter Name="maximumRows" Type="Int32" />
        <asp:Parameter Name="startRow" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

<asp:GridView  ID="grd" runat="server" AutoGenerateColumns="False" 
    DataSourceID="ds"
    AllowPaging="True">
<%--  add columns here --%>
</asp:GridView>

如果您需要从某个控件传递datasource 中的额外参数,您可以添加到SelectParameters

<asp:ControlParameter ControlID="txtID" Name="parameterName" PropertyName="Text" Type="String" />

Namespace.to.Service类中,放方法如下:

public IList<MyObject> FindAll(int maximumRows, int startRow) { ... }
public int FindAllCount(int maximumRows, int startRow) { ... }

如果在数据源中使用了额外的参数,只需将它们也添加到方法中:

public IList<MyObject> FindAll(int maximumRows, int startRow, string parameterName) 
{ 
   /*
      fetch result from database or something;
      'maximumRows' is pageSize
      'startRow' is first result to fetch 'maximumRows' records from database
   */ 
}
public int FindAllCount(int maximumRows, int startRow, string parameterName)
{
   /* 
     take amount of data for. It will be used to create grid footer for pagination;
     parameters are like above.
   */
}

我想这就是你所需要的。

【讨论】:

    猜你喜欢
    • 2010-12-12
    • 2012-03-12
    • 2012-03-31
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    相关资源
    最近更新 更多