LinqDataSource - Can you limit the amount of records returned?(LinqDataSource - 你能限制返回的记录数量吗?)
问题描述
我想在页面上使用 LinqDataSource
控件并限制返回的记录数量.我知道如果我使用背后的代码,我可以做这样的事情:
I'd like to use a LinqDataSource
control on a page and limit the amount of records returned. I know if I use code behind I could do something like this:
IEnumerable<int> values = Enumerable.Range(0, 10);
IEnumerable<int> take3 = values.Take(3);
有谁知道 LinqDataSource
控件是否可以实现这样的功能?
Does anyone know if something like this is possible with a LinqDataSource
control?
[更新]
我将使用 LinqDataSource
和 ListView
控件,不是 GridView 或中继器.LinqDataSource
向导不提供限制返回记录数的功能.高级选项仅允许您启用删除、插入和更新.
I'm going to use the LinqDataSource
with the ListView
control, not a GridView or Repeater. The LinqDataSource
wizard does not provide the ability to limit the number of records return. The Advanced options only allow you to enabled deletes, inserts, and updates.
推荐答案
我遇到了同样的问题.我解决这个问题的方法是使用 LinqDataSource 上的 Selecting 事件并手动返回结果.
I had this same issue. The way I got round this was to use the Selecting event on the LinqDataSource and return the result manually.
例如
protected void lnqRecentOrder_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
DataClassesDataContext dx = new DataClassesDataContext();
e.Result = (from o in dx.Orders
where o.CustomerID == Int32.Parse(Request.QueryString["CustomerID"])
select o).Take(5);
}
这篇关于LinqDataSource - 你能限制返回的记录数量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LinqDataSource - 你能限制返回的记录数量吗?


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01