简单三层分页aspnetpager控件(欢迎指点)
首先添加引用AspNetpager.dll(将.dll文件放在bin中进行引用)
接着添加<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
aspx:
<webdiyer:AspNetPager ID="anp" runat="server" FirstPageText="首页" LastPageText="尾页"
NextPageText="下一页" OnPageChanged="anp_PageChanged" PageSize="50"
PrevPageText="上一页"
CustomInfoHTML="共%RecordCount%条记录,共%PageCount%页 "
ShowCustomInfoSection="Left" ShowPageIndexBox="Never"
CssClass="paginator" CurrentPageButtonClass="cpb" AlwaysShow="True"
CustomInfoSectionWidth="">
</webdiyer:AspNetPager>
aspx.css
if (!IsPostBack)
{
loadpagershow();
anp.RecordCount = br.getIdleCompany_RecordCount();
}
public void loadpagershow()
{
int PageSize= anp.CurrentPageIndex * anp.PageSize;(end)
int pageindex= (anp.CurrentPageIndex - 1) * anp.PageSize + 1;(star)
DataTable dt = br.getIdleCompany_PageRecord(pageindex, PageSize, "");
rptIdleComp.DataSource = dt;
rptIdleComp.DataBind();
}
protected void anp_PageChanged(object sender, EventArgs e)
{
loadpagershow();
}
Dbhelper:
总条数:
public static DataTable getRecordCount(SqlCommand cmd,string strconn)
{
cmd.CommandText = "select count(1) from (" + cmd.CommandText + ") temp ";
return DBUtility.GetDataTable(cmd, strconn);
}
分页:
public static DataTable getPageRecord(SqlCommand cmd, string strconn, int start, int end, string orderby)
{
string subsql = cmd.CommandText;
string sql = "select row_number() over (" + orderby + ") as row_num, t1.* "
+ "from (" + subsql + ") t1 ";
sql = "select * from (" + sql + ") as temp where row_num between " + start.ToString() + " and "
+ end.ToString() + " order by row_num ";
cmd.CommandText = sql;
return DBUtility.GetDataTable(cmd, strconn);
}
DAL:
public static DataTable getIdleCompany_RecordCount()
{
SqlCommand cmd = getIdlecompany_sqlcommand();
return DBHelper.getRecordCount(cmd, DBUtility.connQS);
}
public static DataTable getIdleCompany_PageRecord(int pageIndex, int pageSize, string order_key)
{
string order_by = " order by iss_date desc";
SqlCommand cmd = getIdlecompany_sqlcommand();
return DBHelper.getPageRecord(cmd, DBUtility.connQS, pageIndex, pageSize, order_by);
}
private static SqlCommand getIdlecompany_sqlcommand()
{
string strsql = "";
SqlCommand cmd = new SqlCommand(strsql);
return cmd;
}
BLL:
public int getIdleCompany_RecordCount()
{
int result = 0;
DataTable dt = D_Report.getIdleCompany_RecordCount();
if (dt != null && dt.Rows.Count > 0)
{
result = MyNumber.getInt(dt.Rows[0][0]);
}
return result;
}
public DataTable getIdleCompany_PageRecord(int pageIndex, int pageSize, string order_key)
{
return D_Report.getIdleCompany_PageRecord(pageIndex, pageSize, order_key);
}
完成完成!