Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView is scrolling back to top after row selection

I've got one long GridView control on ma website. 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 enyone know how to avoid this?

like image 382
rafek Avatar asked Jan 23 '09 21:01

rafek


3 Answers

If it's happening during a postback, then in your <%@ Page %> directive you can add the following:

MaintainScrollPositionOnPostback="true"

This was added in .NET 2.0, and adds some JavaScript to the page to ensure that the page scrolls back down to the control that caused the postback.

Works a treat.

like image 90
Zhaph - Ben Duguid Avatar answered Nov 02 '22 05:11

Zhaph - Ben Duguid


I've found another solution. If you have GridView inside scrollable div container I recommend this: Maintain Scroll Position of DIV

like image 43
rafek Avatar answered Nov 02 '22 05:11

rafek


Is it reloading the whole page after selecting the rows ? If so, try to put the GridView in an UpdatePanel, so that the event is sent to the server without actually reloading the whole page.

like image 2
Wookai Avatar answered Nov 02 '22 06:11

Wookai