Sauron Sauron - 13 days ago 9
ASP.NET (C#) Question

Scroll bar reset on GridView in ASP.NET

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.

Answer

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.