代码如下:
PEAEWebSiteDataContext context = new PEAEWebSiteDataContext();
var p = from n in context.tb_News
where n.cname == "校园信息"
select n;
var pp = p.OrderByDescending(tb_News=>tb_News.issuedate).Take(1);var p1 = from n in context.tb_News
where n.cname == "活动安排"
select n;
var pp1 = p1.OrderByDescending(tb_News=>tb_News.issuedate).Take(1);
DataList1.DataSource = pp;
DataList2.DataSource = pp1;
DataList1.DataBind();
DataList2.DataBind();
数据源为dbml,通常使用LinqDataSource的话,绑定的数据行数无法限制。
取而代之,在后台通过Linq to Sql 自定义的选取数据,再绑定在Datalist上即可。