Asp.net 不支持数据源的服务器端分页
我正在从事一个项目,该项目有数十万条来自数据库的记录。我必须在DevExpress网格中显示这个。 网格的默认行为是一次加载所有记录,并在客户端应用分页。 我遇到的问题是,加载页面时需要花费大量时间。要停止此操作,我将在devExpress网格中使用服务器端分页。但我得到一个错误:“Asp.net 不支持数据源的服务器端分页,asp.net,vb.net,visual-studio,devexpress,Asp.net,Vb.net,Visual Studio,Devexpress,我正在从事一个项目,该项目有数十万条来自数据库的记录。我必须在DevExpress网格中显示这个。 网格的默认行为是一次加载所有记录,并在客户端应用分页。 我遇到的问题是,加载页面时需要花费大量时间。要停止此操作,我将在devExpress网格中使用服务器端分页。但我得到一个错误:“数据源不支持服务器端数据分页” 我的网格是“gvList”,我将其属性设置为: gvList.DataSourceForceStandardPaging = True 然后 Dim cmd As New SqlCo
数据源不支持服务器端数据分页
”
我的网格是“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 DhaminalASPxGridView支持三种不同的数据绑定模式: 1) 将所有数据提取到web服务器并由ASPxGridView本身处理时的公共绑定; 2) 服务器端排序和分页。此功能通过激活ASPxGridView的属性打开;在这种情况下,您需要使用ObjectDataSource,因为SQLDataSource不支持服务器端分页。 3) 在DB服务器上实现几乎与网格数据相关的计算(如分组、汇总)时,使用real server模式。上面的链接包含有关此模式的一些有用信息
所以,这个问题最简单的解决方法是使用我的第二个选项。第三个选项功能更强大,但需要一些额外的工作。使用
自定义分页
aproach
因此,您应该将网格与数据源相关联。它可以是objectdatasource或其他。
在数据源中,一些参数应该发送到包含选择和计数方法的类
例如:
网络表单
<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>
在Namespace.to.Service
类中,放置如下方法:
public IList<MyObject> FindAll(int maximumRows, int startRow) { ... }
public int FindAllCount(int maximumRows, int startRow) { ... }
public-IList-FindAll(int-maximumrrows,int-startRow){…}
公共int FindAllCount(int maximumrrows,int startRow){…}
如果使用了datasource中的额外参数,只需将它们添加到方法中即可:
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.
*/
}
public IList FindAll(int-maximumRows、int-startRow、字符串参数name)
{
/*
从数据库或其他地方获取结果;
“maximumRows”是页面大小
“startRow”是从数据库中获取“maximumRows”记录的第一个结果
*/
}
public int FindAllCount(int maximumrrows、int startRow、字符串参数name)
{
/*
获取的数据量。它将用于创建用于分页的网格页脚;
参数如上所示。
*/
}
我想这就是你所需要的。@Magnus Burton,在你发送的链接中,LINQ query正在使用,就像我使用简单查询一样。当然,但它遵循相同的原则。使用您的查询,但添加
限制0,10
以显示前10行Limit 10,10
为了显示第11行到第20行,我在查询strong中添加了Limit 0,10,结果出现了错误。您能举个例子让我知道吗?您能告诉我您的查询吗?谢谢您的回答,但数据集是ObjectDataSource还是SQLDataSource?数据集既不是ObjectDataSource也不是SQLDataSource。这些是特别在ASP.NET中使用的不同精华。如果需要在ASPxGridView中实现分页,请使用我在答案中提供的选项之一。
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.
*/
}