gridview用div滚动条,当gridview资料多时候带滚动条,选中行编辑时重新定位,如何解决。
Gridview 放在UpdatePanel中。我的意思是当点击编辑某一行时滚动条会跑到Gridview顶部,怎么才能让滚动条定位在我点击的那一行呢

解决方案 »

  1.   

    点编辑的时候   js操作就不会跑了
    -----------------------------------
    +1想要固定住滚动条的位置,两个思路:
    1、不刷新界面,比如使用js控制gridview
    2、刷新界面之前记住滚动条的位置
      

  2.   

    提交前记录当前滚动条的位置,提交后页面load完设置滚动条位置
    你可以用隐藏域记录滚动条位置
      

  3.   

    刚才改好了一个页面,但是有一个页面的Gridview中有一列是CheckBox,而且这个checkbox的属性我设置成了AutoPostBack=True,可能因为这个因素同样的办法不行了
      

  4.   

    解决办法:
            1、没有用AJAX时,在原来<%@ Page ……后面增加MaintainScrollPositionOnPostback="true"
            2、当使用了AJAX时以上方法会失效,此时需要在DIV滚动时记住滚动条位置,并在提交后将其恢复
                 a、为外围DIV设置ID及滚动时要执行的代码:
                      <div id="dvGridView" style="overflow: auto; width: 200px; max-height:200px;" runat="server" onscroll="javascript:RecordPostion(this);">
                 b、增加2个隐藏按钮,保存值:
                      <asp:HiddenField ID="dvscrollX" runat="server" />
                      <asp:HiddenField ID="dvscrollY" runat="server" />
                c、脚本:
        <script type="text/javascript" language="javascript">
            function RecordPostion(obj)
            {
                var div1 = obj;
                var sx = document.getElementById('dvscrollX');
                var sy = document.getElementById('dvscrollY');
                
                sy.value = div1.scrollTop;
                sx.value = div1.scrollLeft;
            }
            
            function GetResultFromServer() {
                try {
                    var sx = document.getElementById('dvscrollX');
                    var sy = document.getElementById('dvscrollY');
                    document.getElementById('dvGridView').scrollTop = sy.value;
                    document.getElementById('dvGridView').scrollLeft = sx.value;
                } catch (e) {
                }
            }
        </script>
    d、后台注册脚本:
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            string sjs = "GetResultFromServer();";
            ScriptManager.RegisterClientScriptBlock(this.GridView1, this.GetType(), "", sjs, true);
        }
    我就是用这个办法改好了我期中的一个页面
      

  5.   

    楼主,我最近也遇到了这个问题,我把GridView放在了一个div里面,代码如下:
     <div style="overflow: scroll; height:500px; margin-top:10px;" runat="server" id="dvBody">
    但是当我点击编辑的时候,div就回到了顶部。我看了上面的答复,MaintainScrollPositionOnPostback="true",但是没起作用啊,请问你是怎么做到的呢?