2016-11-21 4 views
0

私の目標は、固定ヘッダーの作業と、ポストバック後にスクロール位置を維持するdiv内のGridViewを持つことです。私は別々に動作する2つの関数を持っていますが、JavaScriptの構文についてはあまり知らないので、関数をマージするのに問題があります。誰かが私を助けることができますか?ありがとう!固定ヘッダーでポストバックを維持するためのJavascript関数をマージする

関連するコード:

<script language="javascript" type="text/javascript"> //FUNCTION 1 Static Header 
        function MakeStaticHeader(gridId, height, width, headerHeight, isFooter) { 
         var tbl = document.getElementById(gridId); 
         if (tbl) { 
          var DivHR = document.getElementById('DivHeaderRow'); 
          var DivMC = document.getElementById('DivMainContent'); 
          var DivFR = document.getElementById('DivFooterRow'); 

          //*** Set divheaderRow Properties **** 
          DivHR.style.height = headerHeight + 'px'; 
          DivHR.style.width = (parseInt(width) - 0) + 'px'; 
          DivHR.style.position = 'relative'; 
          DivHR.style.top = '0px'; 
          DivHR.style.zIndex = '10'; 
          DivHR.style.verticalAlign = 'top'; 
          DivHR.style.alignContent = 'center'; 

          //*** Set divMainContent Properties **** 
          DivMC.style.width = width + 'px'; 
          DivMC.style.height = height + 'px'; 
          DivMC.style.position = 'relative'; 
          DivMC.style.top = -headerHeight + 'px'; 
          DivMC.style.zIndex = '1'; 
          //****Copy Header in divHeaderRow**** 
          DivHR.appendChild(tbl.cloneNode(true)); 
         } 
        } 



        function OnScrollDiv(Scrollablediv) { 
         document.getElementById('DivHeaderRow').scrollLeft = Scrollablediv.scrollLeft; 
        } 


       </script> 
       <script type="text/javascript"> // FUNCTION 2 Maintain Scroll 
        window.onload = function() { 
         var h = document.getElementById("<%=hfScrollPosition.ClientID%>"); 
         document.getElementById("<%=DivMainContent.ClientID%>").scrollTop = h.value; 
        } 
        function SetDivPosition() { 
         var intY = document.getElementById("<%=DivMainContent.ClientID%>").scrollTop; 
         var h = document.getElementById("<%=hfScrollPosition.ClientID%>"); 
         h.value = intY; 
        } 

       function afterpostback() { 
       var h = document.getElementById("<%=hfScrollPosition.ClientID%>"); 
       document.getElementById("<%=DivMainContent.ClientID%>").scrollTop = h.value; 
       } 
       </script> 

       <asp:HiddenField ID="hfScrollPosition" runat="server" Value="0" /> 

        <div style="overflow: hidden;" id="DivHeaderRow"></div> 
        <div style="overflow: scroll;" onscroll="SetDivPosition()" id="DivMainContent" runat="server"> 
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" AutoGenerateColumns="True" ....> </asp:GridView> 
        </div> 

a a

答えて

0

巨大な簡単な修正。追加されました

<div style="overflow: scroll;" onscroll="SetDivPosition(); OnScrollDiv(this)" id="DivMainContent" runat="server"> 

具体的には、機能に追加されたOnScrollDiv(this)に焦点を当てています。魅力のように動作します。

関連する問題