【问题标题】:After selecting an item in Gridview it always returns to the top of the gridview在 Gridview 中选择一个项目后,它总是返回到 gridview 的顶部
【发布时间】:2013-06-19 11:29:55
【问题描述】:

我有 GridView 控件。代码如下。它允许行选择。问题是,当我向下滚动此 GridView 并选择一些底部行时,会发生选择,但整个 GridView 正在滚动回顶部。有谁知道如何避免这种情况?

<div style="overflow: scroll; width: 100%; height: 350px">   
<asp:GridView id="GridView1" runat="server" Width="754px" OnRowDataBound="GridView1_RowDataBound"     DataKeyNames="UniqueID" GridLines="None" ForeColor="#333333" EmptyDataText="There are no data records to display."  DataSourceID="sdsMapsAdd" CellPadding="4" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="False"  OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="UniqueID" Visible="false"   />
<asp:BoundField DataField="Name" HeaderText="Name"  ReadOnly="True" SortExpression="SiteName" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"  />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>

感谢和问候 护理事业

【问题讨论】:

标签: c# asp.net datagrid


【解决方案1】:

通常maintainScrollPositionOnPostBack 会在页面上设置为true,但div 具有用于处理滚动的内联样式。

看看以下内容: Maintain Scroll Bar position of a div within a gridview after a PostBack

【讨论】:

    【解决方案2】:
    I have resolved this issue by using the below code.   
    <div style="overflow: scroll; width: 100%; height: 350px" id= 'scrollDiv'>
    <script type="text/javascript">
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        xPos = $get('scrollDiv').scrollLeft;
        yPos = $get('scrollDiv').scrollTop;
    }
    function EndRequestHandler(sender, args) {
        $get('scrollDiv').scrollLeft = xPos;
        $get('scrollDiv').scrollTop = yPos;
    }
    </script>
    
    Now I need to fix headers in gridview when I scroll down the gridview then headers are not visible. Please advice
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多