实例操作asp.net开发中的分页控件操作
YPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
æ§ä»¶å¨ç½é¡µä¸æ¯é常常ç¨çï¼èæ¯ä¸ªé¡¹ç®å¯¹äºæ§ä»¶çéæ±ä¹æ¯ä¸ä¸æ ·çï¼æ们çç¨åºåé¦éè¦ææ¸ æ¥é¡¹ç®çéæ±ï¼ä¸é¢ç±ç«ææ¯é¢éå°ç¼ä¸ºå¤§å®¶å¸¦æ¥çæ¯å®ä¾æä½asp.netå¼åä¸çå页æ§ä»¶æä½ï¼å¤§å®¶å¯ä»¥è¿å ¥ä¸æè¿è¡åèã
ä¸ã说æ
ããAspNetPager.dllè¿ä¸ªå页æ§ä»¶ä¸»è¦ç¨äºasp.net webformç½ç«ï¼ç°å°æ´ç代ç å¦ä¸
äºã代ç
1ãé¦å å¨æµè¯é¡µé¢Default.aspx页é¢æ·»å å¼ç¨
2ãåä¸ä¸ªRepeaterå表æ§ä»¶ç¨äºæ¾ç¤ºæ°æ®
ãã ãããã ãããããã ãããããã"> ãããã ãã
3ãæ·»å
PageSizeå±æ§æ¯ç¨äºè®¾ç½®æ¯é¡µæ¾ç¤ºçæ°é
4ãåå°ä»£ç ç»å®
//æµè¯æ°æ®æº
private void ShowNews() { ããString strSql = String.Format("select * from News order by time asc"); ããDataTable dtbl = Access.ExecuteDataTable(strSql, null); ããthis.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl); ããthis.rptNews.DataBind(); }
Accessæ¯æµè¯æ°æ®åºè®¿é®ç±»ï¼å¨æåçDemoä¸æä¾ç»å¤§å®¶
5ãå页æ§ä»¶ç¹å»é¡µç äºä»¶
//å页 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { ããthis.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ããShowNews(); }ãã
æåå¥ä¸æ´é¡µä»£ç ï¼
Default.aspx
asp.netå页æ§ä»¶
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowNews(); } } //æµè¯æ°æ®æº private void ShowNews() { String strSql = String.Format("select * from News order by time asc"); DataTable dtbl = Access.ExecuteDataTable(strSql, null); this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl); this.rptNews.DataBind(); } //å页ç¹å»é¡µç äºä»¶ protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); } }
ä¸ãDemo
ããAspNetPagerï¼dllï¼
ããAspNetPageï¼Demoï¼
ä¸è¿°å°±ç±ç«ææ¯é¢éå°ç¼ä¸ºå¤§å®¶å¸¦æ¥çå®ä¾æä½asp.netå¼åä¸çå页æ§ä»¶æä½ï¼å¸æé 读å®æ¬æçä»ç»åé½è½ä¸ºå¤§å®¶å¸¦æ¥ä¸å®ç帮å©ï¼æ谢大家ä¸ç´ä»¥æ¥å¯¹js.aizhan.comçæ¯æã