0

I am using a GridView and ListBox in a page. Gridview contains the data from database bind as DataSource. When clicking on an item in GridView the list box displays the sub items.

My problem occurs when there is a scrollbar in GridView. When I select the last item from the grid view, the sub items are displayed and the scrollbar is going to up. I can't see which item is selected.

fejese
  • 4,601
  • 4
  • 29
  • 36
Sauron
  • 16,668
  • 41
  • 122
  • 174

3 Answers3

0

You will need to generate row ids or record the scroll position before postback. Use the javascript function

yourGridId.scrollTo(x,y) 

and pass the previous x and y positions that you have saved before the postback.

Save the values in a hidden field so that it can be accessed on the server side.

Hemanshu Bhojak
  • 16,972
  • 16
  • 49
  • 64
0

SOLUTION:

Place a hidden field as

<input type="hidden" id="hdnScrollTop" runat="server" value="0" /> 

and in the div add a function

<div id="dvScroll" onscroll="$get('ctl00_ContentPlaceHolder1_hdnScrollTop').value = this.scrollTop;">

JavaScript:

var prm = Sys.WebForms.PageRequestManager.getInstance();         
prm.add_pageLoaded(pageLoaded);
prm.add_beginRequest(beginRequest);
var postbackElement;
function beginRequest(sender, args) {
   postbackElement = args.get_postBackElement();
}
function pageLoaded(sender, args)  {
   var updatedPanels = args.get_panelsUpdated();
   if (typeof (postbackElement) == "undefined") {
      return;
   }
   if (postbackElement.id.indexOf('gridViewList') > -1) {
     try {
         $get("divScroll").scrollTop = $get("ctl00_ContentPlaceHolder1__hdnScrollTop").value;
     }
     catch (Err) {
     }
}}

This solved my problem.

fragilewindows
  • 1,394
  • 1
  • 15
  • 26
Sauron
  • 16,668
  • 41
  • 122
  • 174
0

I suggest you reading the answers to the question Reset scroll position after Async postback - ASP.NET

Community
  • 1
  • 1
Bogdan_Ch
  • 3,328
  • 4
  • 23
  • 39