日期:2014-05-18 浏览次数:20416 次
StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(tid)) { sb.Append(" and typeid=" + tid); } if (!string.IsNullOrEmpty(cname)) { sb.Append(" and title like '%" + cname + "%'"); } Int64 total = 0; string TableName = " yjfw_info "; string ReFieldsStr = " id,InfoID,title,ifoLaiyuan,fabutime,shzt,typeid,tjzt,bzInt"; string OrderString = " bzInt desc,ID desc "; string StrWhere = " 1=1" + sb.ToString(); DataTable dt = pub.FindPageList(out total, PageIndex, 10, StrWhere, TableName, ReFieldsStr, OrderString, "ID"); RepList.DataSource = dt.DefaultView; RepList.DataBind();
------解决方案--------------------
贴点代码,楼主参考
------解决方案--------------------
public IQueryable<Class> Query(Class model) { var query = db.Class.AsQueryable(); if (model != null) { if (!string.IsNullOrEmpty(model.LinkText)) { query = query.Where(a=>a.LinkText.Contains(model.LinkText)); } if (0 != model.LocationID) { query = query.Where(a=>a.LocationID == model.LocationID); } if (null != model.StartDate) { query = query.Where(a=>a.StartDate >= model.StartDate); } if (null != model.EndDate) { query = query.Where(a=>a.EndDate <= model.EndDate); } query = query.Where(a => a.IsDelete == 0); } return query; }