AspNetPager + GridView + ASP.NET AJAX 分页无刷新实现

在网上看到这篇文章《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事件 老是提示莫名奇怪的错误,或者干脆没有翻页效果;

posted @ 2011-04-10 12:38  麻将我会  阅读(855)  评论(0编辑  收藏  举报