2

i have asp:gridview wich contains check box as a column . i have put this gridview in a asp:panel with scroll bars. i have say 500 records in the grid view.

my issue is when, i click on the checkbox (say 200th record) it gets scrolled up to top. Reason here is i want to make some of the cells editable of the GridView and this part is working fine. but it gets scrolled up . then afterwards i have to scroll down again to make changes.

Any suggestions about this behavior.

Html Markup

<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>
Satinder singh
  • 10,100
  • 16
  • 60
  • 102
kumar chaudhari
  • 99
  • 1
  • 6
  • 15
  • set MaintainScrollPositionOnPostback as true in that page directive – Saritha.S.R Oct 03 '13 at 06:32
  • Possible duplicate of [Maintain Panel Scroll Position On Partial Postback ASP.NET](http://stackoverflow.com/questions/5288682/maintain-panel-scroll-position-on-partial-postback-asp-net) – Paritosh Aug 09 '16 at 06:22

4 Answers4

3

To maintain the scroll position for the large web page you can use on of these methods :

1- use Web.config page section <pages maintainScrollPositionOnPostBack="true" />

: this will maintains the scroll positions for all the web site pages.

2- in the page declaration <%@ Page MaintainScrollPositionOnPostback="true" %> : this will maintains the scroll position for this page only.

3- programmatically from code behind System.Web.UI.Page.MaintainScrollPositionOnPostBack = true; : this will maintains the scroll position for this page only (the same as page declration).

Raab
  • 34,778
  • 4
  • 50
  • 65
2
 protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
    {
       gv1.Rows[e.NewEditIndex].findcontrol("chkSelect").focus();

    }
senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36
1

you may try this how to maintain scroll position in ff and some other browser http://aspsnippets.com/Articles/ASPNet-MaintainScrollPositionOnPostback-not-working-in-Firefox-and-Chrome.aspx

kiran
  • 190
  • 1
  • 1
  • 13
0

Can you use a popup div including editable fields ,i think that is the simple way to edit

Nikhil K S
  • 806
  • 1
  • 13
  • 27