关于 javascript:在 PostBack ASP.NET 后维护 DIV 内网格视图的水平滚动条位置

Maintain horizontal Scroll Bar position of a gridview inside a DIV after a PostBack ASP.NET

我有一个很长的网格视图。我想在回发时保持滚动位置。我已经尝试了许多关于堆栈溢出的解决方案,但知道对我有用。

这是我的网格视图

1
2
3
4
5
6
           <asp:GridView ID="gvInventario" runat="server" AutoGenerateColumns="false"  AllowSorting="true" ShowFooter="false" DataKeyNames="componente_id, ubicacion_id, proveedor_id"  PageSize="10"
                ShowHeaderWhenEmpty="true" AllowPaging="True" OnRowEditing="gvInventario_RowEditing" OnRowCancelingEdit="gvInventario_RowCancelingEdit" OnPageIndexChanging="gridView_PageIndexChanging"
                 CellPadding="3"  AllowColumResize="True" onsorting="grdDetails_Sorting" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">    
                <Columns>
                </Columns>
            </asp:GridView>

这是我要防止滚动条静止的按钮的代码

1
2
3
4
5
6
7
8
9
10
                        <ItemTemplate>
                           
                           <%-- --%>
                            <img src="../images/shopping.png" width="20" height="20"/>
                        </ItemTemplate>
                        <EditItemTemplate>
                           
                           
                        </EditItemTemplate>
                    </asp:TemplateField>

这是css。

1
2
3
4
5
6
.largeGridScroll
{
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

这是我的 gridview 的样子。
image

当我按下其中一个按钮时,我不想像图片上那样失去滚动位置。我曾尝试使用 javascript 和 updatepanel 但没有成功,因为所有教程都有垂直滚动而不是像我的那样水平滚动。任何帮助将不胜感激,谢谢。


我在这里回答了 https://www.webcodeexpert.com/2015/09/how-to-maintain-scroll-position-of-html.html 我只需要更改一些小东西即可使其变得可怕
这是我的 css

1
2
3
4
5
6
.largeGridScroll
{
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

这是我的 javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 $(document).ready(function () {
    maintainScrollPosition();
});

function pageLoad() {
    maintainScrollPosition();
}

function setScrollPosition(scrollValue) {
    $('#<%=hfScrollPosition.ClientID%>').val(scrollValue);
}

function maintainScrollPosition() {
    $("#dvScroll").scrollLeft($('#<%=hfScrollPosition.ClientID%>').val());
}

这是我的 aspx

1