ASP.NET How to Maintain Scroll Position within a Datagrid After Postback
<p>I have an aspx page containing a datagrid.  This datagrid is populated in the code-behind via a SQL query and can have anywhere from 1 to 1000 rows.</p>

<p>Users can click on each row and edit the data for that row.  Once they save, however, the datagrid scrolls back to the top, no matter where they were.  I would like to maintain the scroll position within the datagrid so the user can easily edit the next row.  I have the following on my aspx page:</p>

<pre><code>&lt;script src="common.js" type="text/javascript"&gt;&lt;/script&gt;

    &lt;script type = "text/javascript"&gt;

        function setScroll(val) {
            document.getElementById("hidscrollPos").value = val.scrollTop;
        }

        function scrollTo(what) {
            document.getElementById(what).scrollTop =
        document.getElementById("hidscrollPos").value;
        }
&lt;/script&gt;

&lt;body MS_POSITIONING="GridLayout" onload="javascript:scrollTo('divDataGrid')"&gt;
&lt;form id="form1" method="post" runat="server"&gt;
&lt;asp:Panel ID="Panel4" style="left: 0px; position: absolute; top: 354px" runat="server"&gt;
&lt;div id="divDataGrid" style="overflow:scroll;" onscroll="javascript:setScroll(this);"&gt;
    &lt;asp:DataGrid ID="grdItem" runat="server" AllowSorting="True"
        AutoGenerateColumns="False" style="position: absolute; top: 50px" 
        CssClass="grdGrid" Font-Size="X-Small" GridLines="None" Width="97%" 
        Height="4px" CellPadding="1"&gt;


&lt;/asp:DataGrid&gt;
&lt;/div&gt;
&lt;/asp:Panel&gt;
&lt;input type="hidden" id="hidscrollPos" name="scrollPos" value="0" runat="server" /&gt;
&lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p>Within the datagrid I have defined 11 asp:TemplateColumns that I think (hope?) are not relevant to this issue.  I can certainly add in that code if need be.</p>

<p>My .css file has this for grdGrid:</p>

<pre><code>.grdGrid
{
FONT-SIZE: 12px;
FONT-FAMILY: Verdana;
BACKGROUND-COLOR: white
}
</code></pre>

<p>I am using Visual Studio 2008 and IE9.  Users will be using either IE8 or IE9.</p>

<p>Any help would be much appreciated!</p>
