日期:2014-05-18  浏览次数:20447 次

DataGrid 转页要双击,是怎么回事?
RT
html:

<asp:DataGrid   id= "DataGrid1 "     runat= "server "   AllowPaging= "True "   PageSize= "3 "   CellPadding= "4 "     Font-Names= "Verdana "   Font-Size= "8pt "   OnPageIndexChanged= "DataGrid1_PageIndexChanged ">
<PagerStyle   NextPageText= "[下一页] "     PrevPageText= "   [上一页] "     > </PagerStyle>

cs

  protected   void   Page_Load(object   sender,   EventArgs   e)
        {
              //数据绑定
             
          }

        protected   void   DataGrid1_PageIndexChanged(object   source,   System.Web.UI.WebControls.DataGridPageChangedEventArgs   e)
        {
                DataGrid1.CurrentPageIndex   =   e.NewPageIndex;
        }

转页没问题,不过要双击才转能转页,不正常啊~

------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Bind();
}
}

public void Bind()
{
//写你自己页面加载时的绑定方法
}

protected void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//绑定一下
Bind();
}