首页 > 代码库 > 如何使用 aspnetpager
如何使用 aspnetpager
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %> <webdiyer:AspNetPager id="AspNetPager1" runat="server" ShowPageIndexBox="Always" PageSize="20" OnPageChanged="AspNetPager1_PageChanged" TextBeforeInputBox="转到第 " TextAfterInputBox=" 页 " ShowPageIndex="False" ShowInputBox="Always" ShowCustomInfoSection="Left" PrevPageText="上一页" NextPageText="下一页" LastPageText="尾页" FirstPageText="首页" AlwaysShow="True" CustomInfoSectionWidth="600" CustomInfoTextAlign="NotSet" LayoutType="Table"> </webdiyer:AspNetPager> <webdiyer:AspNetPager ID="AspNetPager2" runat="server" CloneFrom="AspNetPager1"> </webdiyer:AspNetPager>
public void checkCase() { string strSql = " ID>0"; int num = bll.GetRecordCount(strSql); AspNetPager1.RecordCount = num; DataSet ds = bll.GetAspNetPagerDataSet(strSql, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize); if (ds.Tables[0].Rows.Count > 0) { this.Repeater1.DataSource = ds.Tables[0].DefaultView; this.Repeater1.DataBind(); AspNetPager1.CustomInfoHTML = "共:<font color=\"red\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font> 条记录"; AspNetPager1.CustomInfoHTML += " 总页数:<font color=\"red\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font> 页"; AspNetPager1.CustomInfoHTML += " 每页显示:<font color=\"red\"><b>" + AspNetPager1.PageSize.ToString() + "</b></font> 条"; AspNetPager1.CustomInfoHTML += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font> "; } }
bll
/// <summary> /// 获得aspnetpager分页数据 /// </summary> public DataSet GetAspNetPagerDataSet(string whereSql, int mypageindex, int mypagesize) { return dal.GetAspNetPagerList(whereSql, mypageindex, mypagesize); }
DAL
/// <summary> /// 获得AspNetPager分页数据列表 /// </summary> public DataSet GetAspNetPagerList(string strWhere, int mypageindex, int mypagesize) { StringBuilder strSql = new StringBuilder(); strSql.Append(" SELECT ID,sTitle,sContent,sAuthor,sAuthorTel,sAuthorQQ,sAuthorEmail,toDepart,ifPass,PubDate "); strSql.Append(" FROM QuestionBook "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by ID desc"); return SQLHelper.ExecuteWebDiyerDataset(SQLHelper.DBCONNECTIONSTRING, CommandType.Text, strSql.ToString(), mypageindex, mypagesize); }
DBTtility
#region 为webdiyer分页控件做的 DataSet 传递参数进来 DataSet ExecuteWebDiyerDataset(string connString, CommandType cmdType, string cmdText,int mypageindex,int mypagesize, params SqlParameter[] cmdParms) public static DataSet ExecuteWebDiyerDataset(string connString, CommandType cmdType, string cmdText, int mypageindex, int mypagesize, params SqlParameter[] cmdParms) { SqlDataAdapter myAdapter = new SqlDataAdapter(); myAdapter.SelectCommand = new SqlCommand(); using (SqlConnection conn = new SqlConnection(connString)) { PrepareCommand(myAdapter.SelectCommand, conn, null, cmdType, cmdText, cmdParms); DataSet ds = new DataSet(); myAdapter.Fill(ds, mypagesize * (mypageindex - 1), mypagesize, "dtable"); myAdapter.SelectCommand.Parameters.Clear(); return ds; } } #endregion
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。