aspnetpager在不跟数据控件结合的时候,该如何分页? 页面没有数据控件,所有数据都在dataset里面,页面输出用for循环,请问能用aspnetpager实现分页不?如果可以,该如何做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我愿意洗耳恭听,您可以发邮件到[email protected],我自己观摩研究 /// <summary> /// 获取记录数 /// </summary> /// <param name="table"></param> /// <param name="cond">格式:Where ...</param> /// <returns></returns> public int GetRowCount(string table, string cond) { string query = string.Format("Select count(*) From {0} {1}", table, cond); DataSet ds = db.GetDataSet(query); if (ds != null) { if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { return Galsun.Common.Utils.StrToInt(ds.Tables[0].Rows[0][0].ToString(), 0); } } return 0; } /// <summary> /// /// </summary> /// <param name="table"></param> /// <param name="rowpage"></param> /// <param name="rowcount"></param> /// <param name="orderFid"></param> /// <param name="Conditions"></param> /// <returns></returns> public DataSet GetinfoList(string table, int rowpage, int rowcount, string orderFid, string Conditions) { 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 + 1, rowpage * rowcount, orderFid, Conditions, table); //string query = "Select top {0} * From {1} {2} and id not in(Select top {3} id From {1} {2} Order by {4}) Order by {4}"; //query = string.Format(query, rowcount, table, Conditions, (rowpage - 1) * rowcount + 1, orderFid); return db.GetDataSet(query); }//应用都是一样的 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bindData(); } } void bindData() { string cond = " Where isCheck=1 and sid=2 "; //初使化一个SQL语句str //绑定数据 AspNetPager1.RecordCount = GetRowCount("gl_NewsSystem", cond); DataTable dt = GetinfoList("gl_NewsSystem", AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, " OrderID DESC,FBDate DESC,id DESC", cond); foreach(DataRow item in dt.Rows) { ....... } } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { bindData();//更新页面数据 } public void Bind() { int Top = 0; string strWhere = " IsTrue=1 and Type=5 "; string filedOrder = "Time desc"; BLL.BOOK book = new BLL.BOOK(); DataSet set = new DataSet(); set = book.GetList(Top, strWhere, filedOrder); int pagesize = AspNetPager1.PageSize; int currentpage = AspNetPager1.CurrentPageIndex; imd = book.GetListTo(Top, strWhere, filedOrder, pagesize * (currentpage - 1), pagesize); AspNetPager1.RecordCount = set.Tables[0].Rows.Count; } 这是我自己写的一个还不错的分页事件!!!book.GetListTo()就是分页,看看da.Fill()方法就知道了 请好心人总结asp.net前台验证正则表达式 急啊 网站在本地上没问题到服务器上面有问题 GridView如何隐藏Command Button Graphics如何压缩图像质量 如何在后台设置图文混排 询问关于cookies(登陆时使用)的问题 获取<div>的大小 Target 框架 以及页面跳转问题 初到ASP.NET的领域,能给我解释一下ASP.NET吗? 水晶报表的问题! 时间字段的比较问题! 求一个博客模块
/// <summary>
/// 获取记录数
/// </summary>
/// <param name="table"></param>
/// <param name="cond">格式:Where ...</param>
/// <returns></returns>
public int GetRowCount(string table, string cond)
{
string query = string.Format("Select count(*) From {0} {1}", table, cond);
DataSet ds = db.GetDataSet(query);
if (ds != null)
{
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return Galsun.Common.Utils.StrToInt(ds.Tables[0].Rows[0][0].ToString(), 0);
}
}
return 0; }
/// <summary>
///
/// </summary>
/// <param name="table"></param>
/// <param name="rowpage"></param>
/// <param name="rowcount"></param>
/// <param name="orderFid"></param>
/// <param name="Conditions"></param>
/// <returns></returns>
public DataSet GetinfoList(string table, int rowpage, int rowcount, string orderFid, string Conditions)
{ 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 + 1, rowpage * rowcount, orderFid, Conditions, table); //string query = "Select top {0} * From {1} {2} and id not in(Select top {3} id From {1} {2} Order by {4}) Order by {4}";
//query = string.Format(query, rowcount, table, Conditions, (rowpage - 1) * rowcount + 1, orderFid);
return db.GetDataSet(query); }
//应用都是一样的 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindData();
}
}
void bindData()
{ string cond = " Where isCheck=1 and sid=2 "; //初使化一个SQL语句str //绑定数据
AspNetPager1.RecordCount = GetRowCount("gl_NewsSystem", cond);
DataTable dt = GetinfoList("gl_NewsSystem", AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, " OrderID DESC,FBDate DESC,id DESC", cond);
foreach(DataRow item in dt.Rows)
{
.......
}
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bindData();//更新页面数据
}
public void Bind()
{
int Top = 0;
string strWhere = " IsTrue=1 and Type=5 ";
string filedOrder = "Time desc";
BLL.BOOK book = new BLL.BOOK();
DataSet set = new DataSet();
set = book.GetList(Top, strWhere, filedOrder);
int pagesize = AspNetPager1.PageSize;
int currentpage = AspNetPager1.CurrentPageIndex;
imd = book.GetListTo(Top, strWhere, filedOrder, pagesize * (currentpage - 1), pagesize); AspNetPager1.RecordCount = set.Tables[0].Rows.Count;
}