LinqDataSource - Can you limit the amount of records returned?

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 e. G 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); }.

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. E.g.

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 cannot limit the results within the LinqDataSource control. Because Linq uses deferred execution, the expectation is that the presentation control will do the recordset limits.

Yes, you can do this with a ListView control. The trick is to use the DataPager control within the LayoutTemplate, like so: Normally, you would include controls inside the DataPager like first, last, next, and previous. But if you just make it empty, then you will only see the three results that you desire.

Hope this helps.

1 sorry I have a Q about your answer. If I use your solution can uoy tell me about page Weight?! The LinqDataSource selects all records but ListView just shows 3 records.

Is it such a overhead on the page? – mahdiahmadirad Jul 5 '10 at 6:49.

You could base your Linq query on a stored proc that only returns x number of rows using a TOP statement. Remember just because you can do all your DB code in Linq doesn't mean you should. Plus, you can tell Linq to use the same return type for the stored proc as the normal table, so all your binding will still work, and the return results will be the same type.

You can put event Selecting of LinqDataSource: protected void ldsLastEntries_Selecting(object sender, LinqDataSourceSelectEventArgs e) { e.Arguments. MaximumRows = 10; }.

I know that if you use a paging repeater or gridview with the linqdatasource it will automatically optimize the number of results returned, but I'm also pretty sure in the datasource wizard you can go to advanced options and limit it to SELECT TOP 3 FROM which should allow you to do what you need.

No, you cannot limit the results within the LinqDataSource control. Because Linq uses deferred execution, the expectation is that the presentation control will do the recordset limits. Yes, you can do this with a ListView control.

Normally, you would include controls inside the DataPager like first, last, next, and previous.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions