5.GetDivPager拼接字符串
queryString 如果需要在URL加参数,比如:&charset=utf-8
ds 从存储过程的取得数据集
dt 将列表数据返回
返回值 HTML标签 ?
public string GetDivPager(string queryString, DataSet ds, out DataTable dt) { StringBuilder sp = new StringBuilder(); int PageSize = 10; if (ds != null && ds.Tables.Count > 0) { dt = ds.Tables[0]; int TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString()); int rowCount = (TotalCount % PageSize != 0) ? TotalCount / PageSize + 1 : TotalCount / PageSize; if (dt != null && dt.Rows.Count > 0) { sp.AppendFormat("总记录:{0}", TotalCount); sp.AppendFormat(" 页码:{0}/{1} ", PageIndex, rowCount); sp.AppendFormat(" 每页:{0}
", PageSize); sp.AppendFormat(""); sp.AppendFormat(" 首页 ", "?page=1" + queryString); if (PageIndex > 1) { sp.AppendFormat(" < 上一页 ", "?page=" + (PageIndex - 1) + queryString); } int temp = 0; int loopc = rowCount > 10 ? 10 : rowCount; for (int i = 0; i < loopc; i++) { temp = i + 1; if (PageIndex > 10) { temp = (PageIndex - 10) + i + 1; } sp.AppendFormat(" {2}", PageIndex == temp ? "active" : "", "?page=" + temp + queryString, temp); } if (PageIndex != rowCount) { sp.AppendFormat(" 下一页 >", "?page=" + (PageIndex + 1) + queryString); } sp.AppendFormat(" 尾页", "?page=" + rowCount + queryString); sp.AppendFormat(""); } } else { dt = null; } return sp.ToString(); }
?
?
6.页面显示
?
| 序号 | 用户名 | 密码 | 创建时间 | |
|---|---|---|---|---|
| " /> | <%=abc++ %> | <%=item["UserName"]%> | <%=item["PASSWORD"]%> | <%=Convert.ToDateTime(item["CreateTime"]).ToString("yyyy-MM-dd hh:mm:ss") %> |
?
OK!