LinqDataSource - Can you limit the amount of records returned?

后端 未结 6 1387
抹茶落季
抹茶落季 2021-01-01 09:14

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:

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 09:28

    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.

提交回复
热议问题