public class MyTest { /// <summary> /// 获取测试数据 /// </summary> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <returns></returns> public List<Article> GetArticleList(string key, int PageSize, int CurrentCount, out int TotalCount) { string tabName = string.Format("Article"); string strWhere = " 1=1"; if (!string.IsNullOrEmpty(key)) { //SQL关键字过滤 包含关键字则不拼接SQL if (!SqlInjection.GetString(key)) { strWhere += string.Format(" AND (Title LIKE '%{0}%' OR Content LIKE '%{0}%')", key); } } string Order = string.Format("ID ASC"); DataSet ds = SqlHelper.GetList(SqlHelper.connStr, Order, PageSize, CurrentCount, tabName, strWhere, out TotalCount); List<Article> list = new List<Article>(); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { Article model = new Article(); model.ID = Convert.ToInt32(dr["ID"]); model.Title = dr["Title"].ToString(); model.Content = dr["Content"].ToString(); list.Add(model); } } return list; } }
效果图:(需要引用CSS)