window.scrollto无法在gridview pageindexchanging中工作 [英] window.scrollto not working in gridview pageindexchanging

查看:71
本文介绍了window.scrollto无法在gridview pageindexchanging中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  grdArchive_PageIndexChanging(对象发​​件人,GridViewPageEventArgs e)
{
grdArchive.PageIndex = e.NewPageIndex;
GetArchive();

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append( < script language ='javascript'>);
sb.Append( window.scrollTo(0,0););
sb.Append( < / script>);
System.Web.UI.ScriptManager.RegisterStartupScript( this this .GetType(), JCall1,sb.ToString(), false < /跨度>);
}



我在GridView事件 grdArchive_PageIndexChanging 中添加了此JavaScript代码,以便转到页面顶部使用新数据刷新网格后,但这不起作用。



请帮我这样做。

解决方案

使用 PageIndexChanged 事件而不是 PageIndexChanging 事件。

无需使用字符串buider附加脚本标签。

只需JavaScript代码即可。

  protected   void  grdArchive_PageIndexChanged( object  sender,EventArgs e)
{
System.Web.UI.ScriptManager.RegisterStartupScript( this this .GetType(), ajax_client_script < span class =code-string> window.scrollTo(0,0);, true );
}



试试这个让我知道。



谢谢......


protected void grdArchive_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       grdArchive.PageIndex = e.NewPageIndex;
       GetArchive();

       System.Text.StringBuilder sb = new System.Text.StringBuilder();
       sb.Append("<script language='javascript'>");
       sb.Append(" window.scrollTo(0,0);");
       sb.Append("</script>");
       System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JCall1", sb.ToString(), false);
   }


I have added this JavaScript code inside GridView event grdArchive_PageIndexChanging for going to top of the page after grid refresh with new data, but this is not working.

Please help me to do this.

解决方案

Use PageIndexChanged Event instead of PageIndexChanging Event.
And no need to use string buider to append the script tags.
Just the JavaScript code will do.

protected void grdArchive_PageIndexChanged(object sender, EventArgs e)
{
      System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax_client_script", "window.scrollTo(0,0);", true);
}


Try this and let me know.

Thanks...


这篇关于window.scrollto无法在gridview pageindexchanging中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆