LinqDataSource - Can you limit the amount of records returned?

后端 未结 6 1419
抹茶落季
抹茶落季 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:37

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

提交回复
热议问题