在網上看到這篇文章《AspNetPager + GridView + ASP.NET AJAX 分頁無重新整理實現 》 感覺收穫很大, 這裡推薦給大家,
public partial class HYZXLIST : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetData(); } } private void GetData() { Info i = new Info(); int classid = 1; if (!string.IsNullOrEmpty(Request.QueryString["classid"])) { classid = int.Parse(Request.QueryString["classid"].ToString()); } int pageindex = 1; //if (Request["page"] != null) //{ // pageindex = Convert.ToInt32(Request["page"]); //} if (AspNetPager1.CurrentPageIndex < 1) { pageindex = 1; } else { pageindex = AspNetPager1.CurrentPageIndex; } int pagenum = AspNetPager1.PageSize; int recordcount; string classname; ListView1.DataSource = i.GetInfoByClassID(pageindex, pagenum, out recordcount, classid, out classname); ListView1.DataBind(); titleleft.InnerText = classname; titleright.InnerHtml = "你現在的位置>>" + classname; AspNetPager1.RecordCount = recordcount; } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; GetData(); } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { }}
可以看到這裡用的是page_changing事件;
剛開始使用的pagechanged事件 老是提示莫名奇怪的錯誤,或者乾脆沒有翻頁效果;