数据源不支持服务器端分页



我正在做一个项目,其中有成千上万的记录来自数据库。我必须在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()

有谁能告诉我我哪里做错了吗?

谢谢. .Anjum Dhamial

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

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

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

使用Custom Pagination方法

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

一个例子:Web表单

<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.
   */
}

我想这就是你所需要的。

最新更新