Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got GridView control. code is given below. It allows row selection. The problem is, when I scroll down this GridView and select some of the bottom rows the selection occurs, but whole GridView is scrolling back to top. Does anyone know how to avoid this?


XML
<div id="grd1" 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>
Posted

If you are using asynchronous postback (update panel etc.)..then have a look at ..
maintain-scroll-position-after-asynchronous-postback.aspx[^]

and also this..
http://www.4guysfromrolla.com/articles/111704-1.aspx[^]
 
Share this answer
 
Comments
vibsg 24-Jun-13 15:09pm    
Hi,

I have already used this code for fixing the header after long search. Please see this code link.

[^]

Could you please advice how would I maintain scroll position using this code.?

ALSo, IF i use Hi OI,

I have already used this code for fixing the header after long search. Please see this code link.

[^]

Could you please advice how would I maintain scroll position using this code.?


Thanks & Regards
vibsg 24-Jun-13 15:11pm    
Hi, I have already used this code for fixing the header after long search. Please see this code link. http://www.etechpulse.com/2013/05/how-to-make-fixed-header-gridview.html?showComment=1372086873889#c1287060250175172910 Could you please advice how would I maintain scroll position using this code.?

Also, I have used maintain-scroll-position-after-asynchronous-postback.aspx[^] still no luck.

Thanks & Regards Care Career
[no name] 24-Jun-13 17:08pm    
I am not sure why is it not working for you...If you are looking at a grid with all this functionality inbuilt, here is an enhancement of asp.net grid-view..http://ideasparks.codeplex.com/
Please have a look at the following article on CP:
Scroll Gridview while Maintaining Scroll Position[^]

Good luck,
OI
 
Share this answer
 
Comments
vibsg 24-Jun-13 15:10pm    
Hi OI,

I have already used this code for fixing the header after long search. Please see this code link.

http://www.etechpulse.com/2013/05/how-to-make-fixed-header-gridview.html?showComment=1372086873889#c1287060250175172910

Could you please advice how would I maintain scroll position using this code.?


Thanks & Regards
Care Career
vibsg 24-Jun-13 15:20pm    
ALso, I have run your project however header is not fixed when I scroll down the gridview and sorting is also not available . Please advice. Thanks.
Orcun Iyigun 24-Jun-13 17:20pm    
First of all you did not mention you want to keep the headers on your gridview in your question? How would I know? I can not read your mind you should have specified it.

Secondly your link is pretty straight forward what is the problem you are having difficulty with?
vibsg 25-Jun-13 0:12am    
Headers are fixed.The problem is, when I scroll down this GridView and select some of the bottom rows the selection occurs, but whole GridView is scrolling back to top.Only this issue I am facing now. Thanks.
Orcun Iyigun 25-Jun-13 1:29am    
I am not sure if this will solve your issue but it won't hurt:
Try these 2:
*Page.MaintainScrollPositionOnPostback = true; (place this in your codebehind)
or in design view You can code MaintainScrollPosition = "true"
Another alternative:
Place the following code into the <system.web> section of your .config file:
<pages maintainScrollPositionOnPostBack="true">
<controls>
<add tagprefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<add tagprefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

</pages>
Beware this is for framework 3.5.
Hi OI,

I have already used this code for fixing the header after long search. Please see this code link.

[^]

Could you please advice how would I maintain scroll position using this code.?


Thanks & Regards
Care Career
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900