asp.Netページングsql文(aspnetpagerと結合)
2536 ワード
データベース操作クラス:
フロント:
バックグラウンド:
///
///
///
///
public string getTotal()
{
StringBuilder sb = new StringBuilder();
sb.Append("select count(*) total from Test");
DataTable dt = DBHelper.ExecuteDt(sb.ToString());
return dt.Rows[0][0].ToString();
}
///
/// , , 。
///
///
///
///
public DataTable getPagesData(int pageNum, int currentPage)
{
StringBuilder sb = new StringBuilder();
sb.Append("select top " + pageNum + " * from Test where ");
sb.Append("ID not in (select top " + pageNum * currentPage + " ID from Test)");
return DBHelper.ExecuteDt(sb.ToString());
}
フロント:
バックグラウンド:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class sqlPager_Default : System.Web.UI.Page
{
BLL.Test test = new BLL.Test();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AspNetPager1.RecordCount = Convert.ToInt32(test.getTotal());// ..
Bind();
}
}
private void Bind()
{
this.gvSql.DataSource = test.getPagesData(Convert.ToInt32(AspNetPager1.PageSize), AspNetPager1.CurrentPageIndex - 1);
this.gvSql.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Bind();
}
}