/// <summary>
/// 分页方法
/// </summary>
/// <param name="ReSource">Repeater控件 </param>
/// <param name="RePager">AspNetPager分布控件</param>
/// <param name="PageIndex">当前页</param>
/// <param name="strWhere">搜索条件</param>
/// <param name="TableName">查询的表或视图</param>
/// <param name="keyField">排序字段</param>
public static void RepeaterBind(Repeater ReSource, AspNetPager RePager, int PageIndex, string strWhere, string TableName, string keyField)
{
int Acount = GetAllCount(strWhere, TableName);
if (Acount > 0)
{
ReSource.Visible = true;
RePager.Visible = true;
ReSource.DataSource = GetList(PageIndex, strWhere, TableName, keyField);
ReSource.DataBind();
RePager.RecordCount = Acount;
RePager.PageSize = PAGESIZE;
#region 分页样式
RePager.CustomInfoText = "共<font style=/"font-weight:bord;/"><b> " + RePager.RecordCount.ToString() + " </b></font>条数据";
RePager.CustomInfoText += " 总页数:<font style=/"font-weight:bord;/"><b> " + RePager.PageCount.ToString() + " </b></font>";
RePager.CustomInfoText += " 当前页:<font style=/"font-weight:bord;/"><b>" + RePager.CurrentPageIndex.ToString() + "</b></font>";
#endregion
}
else
{
ReSource.Visible = false;
RePager.Visible = false;
}
}
/// <summary>
/// 分页获取数据列表
/// </summary>
private static DataSet GetList(int PageIndex, string strWhere, string TableName, string keyId)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = TableName;
parameters[1].Value = keyId;
parameters[2].Value = PAGESIZE;
parameters[3].Value = PageIndex;
parameters[4].Value = 1;//返回记录条数
parameters[5].Value = 1;
parameters[6].Value = strWhere;
return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
}
private static int GetAllCount(string StrWhere, string TableName)
{
if (StrWhere.Trim() == "")
{
return Convert.ToInt32(DbHelperSQL.GetSingle("select count(1) from " + TableName));
}
else
{
return Convert.ToInt32(DbHelperSQL.GetSingle("select count(1) from " + TableName + " where " + StrWhere));
}
}