页面后台写法
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) { BindData();
}
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindData();
}
public void BindData()
{
PageDataBaseOptater pdo = new PageDataBaseOptater();
AspNetPager1.RecordCount = pdo.GetRowCount("表名","where条件");
AspNetPager1.PageSize = pageSize;//pagesize可以设定
string cond = " where 条件";
DataSet ds = pdo.GetinfoList("表", AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, "记录的Id DESC", cond, "id名称"); Repeater1.DataSource = ds; Repeater1.DataBind();
}
dao层:
public class PageDataBaseOptater
{
/// <summary>
/// 获取记录数
/// </summary>
public int GetRowCount(string table,string where条件可以没有)
{
//获取表的记录总数
}
public DataSet GetinfoList(string table, int rowpage, int rowcount,
string orderFid, string Conditions,string colum_id)
{
//sqlserver2005的
//string query = "Select * From "
// + "(Select *,ROW_NUMBER() OVER(ORDER BY {2}) as RowNum From {4} {3}) as newTable "
// + "Where (RowNum BETWEEN ({0}) AND ({1}))";
//query = string.Format(query, (rowpage - 1) * rowcount , rowpage * rowcount, orderFid, Conditions, table);
string query = "Select top {0} * From {1} {2} and {3} not in(Select top {4} {3} From {1} {2} Order by {5}) Order by {5}";
query = string.Format(query, rowcount, table, Conditions, colum_id, (rowpage- 1) * rowcount, orderFid);
DataDao dao = new DataDao();
return dao.PageGetDataSet(query);
}
}
控件下载:http://download.csdn.net/detail/yysyangyangyangshan/3625510