ASP.NET的数据分页的div,a标签封装字符串
queryString 表示分页时需要传到参数,比如:&charset=utf-8
ds 表示查询的数据列表,和总页码
dt 表示将数据列表返回
返回结果 是页面的div
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(" <p class=\"fl\">总记录:<span id=\"sum\">{0}</span>", TotalCount);
sp.AppendFormat(" 页码:<em><b id=\"current\">{0}</b>/<span id=\"count\">{1}</span></em> ", PageIndex, rowCount);
sp.AppendFormat(" 每页:<span id=\"eachPage\">{0}</span></p> ", PageSize);
sp.AppendFormat(" <div class=\"pagination fr\"> ");
sp.AppendFormat(" <a class=\"disabled\" href='{0}'>首页</a> ", "?page=1" + queryString);
if (PageIndex > 1)
{
sp.AppendFormat(" <a href='{0}'>< 上一页 </a>", "?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(" <a class=\"{0}\" href='{1}'>{2}</a>", PageIndex == temp ? "active" : "", "?page=" + temp + queryString, temp);
}
if (PageIndex != rowCount)
{
sp.AppendFormat(" <a href='{0}'>下一页 ></a>", "?page=" + (PageIndex + 1) + queryString);
}
sp.AppendFormat(" <a href='{0}'>尾页</a>", "?page=" + rowCount + queryString);
sp.AppendFormat(" </div>");
}
}
else
{
dt = null;
}
return sp.ToString();
}
至于存储过程,下节呈现