Click here to Skip to main content
12,076,586 members (49,400 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#2.0 C#
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?


<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 24-Jun-13 9:12am
vibsg451
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
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
learner'sbug 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/
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Please have a look at the following article on CP:
Scroll Gridview while Maintaining Scroll Position[^]

Good luck,
OI
  Permalink  
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 section of your .config file:
<pages maintainScrollPositionOnPostBack="true">




</pages>
Beware this is for framework 3.5.
vibsg 25-Jun-13 2:19am
   
Tried these 2 options still no luck :-( .
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 24 Jun 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100