日期:2014-05-17  浏览次数:20373 次

用过AspNetPager控件的朋友进来看下这是什么问题.关于UrlPaging的.谢谢!
先看代码:
HTML code

        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" 
            onpagechanged="AspNetPager1_PageChanged" AlwaysShow="true" UrlPaging="true">
        </webdiyer:AspNetPager>


C# code

if (!IsPostBack)
            {
bind();
}
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bind();
        }
        private void bind()
        {

        }



现在的问题是UrlPaging="true"以后,每次页面加载都需要运行两次bind().也就是说,不管AspNetPager1是不是Changed,都运行了AspNetPager1_PageChanged(...). 这是什么原因呢?如何解决?

------解决方案--------------------
protected void anpPro_PageChanging(object sender, Wuqi.Webdiyer.PageChangingEventArgs e)
{
anpPro.CurrentPageIndex = e.NewPageIndex;
int classId = PCHelper.GetQueryStringID("classId");
Bind(classId);
}
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}

public void Bind()
{
int pagecnt = 20;
int currentpage = AspNetPager1.CurrentPageIndex;

AspNetPager1.RecordCount = Convert.ToInt32(DBUtility.DbHelperSQL.GetSingle("sql语句"));//查询出总条数
AspNetPager1.PageSize = pagecnt;

Repeater1.DataSource = DBUtility.DbHelperSQL.Query("sql语句");
Repeater1.DataBind();

}

 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind();
}