使用LinqDataSource - 你能限制返回的记录是多少? [英] LinqDataSource - Can you limit the amount of records returned?

查看:247
本文介绍了使用LinqDataSource - 你能限制返回的记录是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个页面上的的LinqDataSource 控制和限制返回的记录数量。我知道,如果我使用code后面我可以做这样的事情:

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 控制?

[更新]

我要使用的LinqDataSource 的ListView 控制的的一个GridView或Repeater。在的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的选择事件并手动返回结果。

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 - 你能限制返回的记录是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆