我有 asp:gridview 至极包含复选框作为列。 我已将此 gridview 放在带有滚动条的 asp:panel 中。 我在 GridView 中说有 500 条记录。
我的问题是,当我点击复选框(比如第 200 条记录)时,它会向上滚动到顶部。 这里的原因是我想让 GridView 的一些单元格可编辑,这部分工作正常。但它会向上滚动。然后我必须再次向下滚动以进行更改。
关于此行为的任何建议。
HTML 标记
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:Panel runat="server" ID="p1" Height="250px" Width="100%" ScrollBars="Both">
<asp:GridView ID="gv1" runat="server" CellPadding="3" AutoGenerateColumns="False"
GridLines="Vertical" BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" Width="108%">
<Columns>
<asp:TemplateField HeaderStyle-Width="20px" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true"
OnCheckedChanged="checkBoxID_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OT Hours">
<ItemStyle Height="35px" Width="60px"/>
<ItemTemplate>
<asp:TextBox runat="server" ID="txtOThrs" Text= '<%# Bind("othours") %>' Width="60px"
Font-Size="10px" ReadOnly="true" AutoPostBack="true"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OTAuth">
<ItemStyle Height="35px" Width="60px"/>
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddlOTAuth" AutoPostBack="true" Font-Size="10px"
Width="80px" Height="20px" Enabled="false" Text='<%# Eval("OTAuthorized") %>' >
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
最佳答案
要保持大型网页的滚动位置,您可以使用以下方法之一:
1- 使用 Web.config 页面部分 <pages maintainScrollPositionOnPostBack="true" />
:这将维护所有网站页面的滚动位置。
2-在页面声明<%@ Page MaintainScrollPositionOnPostback="true" %>
: 这将仅保留此页面的滚动位置。
3- 以编程方式从代码隐藏 System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;
: 这将仅维护此页面的滚动位置(与页面声明相同)。
关于c# - gridview 滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19152212/