Let me make use of a LinqDataSource control on the page and limit the quantity of records came back. I understand basically use code behind I possibly could make a move such as this:

IEnumerable<int> values = Enumerable.Range(0, 10);
IEnumerable<int> take3 = values.Take(3);

Does anybody determine if something similar to you could do having a LinqDataSource control?


I am likely to make use of the LinqDataSource using the ListView control, not a GridView or Repeater. The LinqDataSource wizard doesn't provide a chance to limit the amount of records return. The Advanced options only permit you to enabled removes, card inserts, and updates.

I'd this same problem. The way in which I acquired round sony playstation make use of the Choosing event around the LinqDataSource and return the end result by hand.


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);

Yes and No.

No, you can't limit the outcomes inside the LinqDataSource control. Because Linq uses deferred execution, the expectation would be that the presentation control is going to do the recordset limits.

Yes, this can be done having a ListView control. The secret is by using the DataPager control inside the LayoutTemplate, like so:

  <div id="itemPlaceholder" runat="server" />
  <asp:DataPager ID="DataPager1" runat="server" PageSize="3">

Normally, you'd include controls within the DataPager like first, last, next, and former. But when you simply allow it to be empty, then you'll only begin to see the three results that you want.

Hope this can help.

You can base your Linq query on the saved proc that only returns x quantity of rows utilizing a TOP statement. Remember just since you can do all of your DB code in Linq does not mean you need to. Plus, you are able to tell Linq to make use of exactly the same return type for that saved proc because the normal table, so that all your binding will still work, and also the return results would be the same type

You are able to put event Choosing of LinqDataSource: protected void ldsLastEntries_Choosing(object sender, LinqDataSourceSelectEventArgs e)

I understand that if you are using a paging repeater or gridview using the linqdatasource it'll instantly optimize the amount of results came back, but I am also confident within the datasource wizard you can turn to advanced options and limit it to

Choose Best Three FROM

that ought to permit you to do the thing you need