復制代碼 代碼如下:
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上即可。