views:

1216

answers:

3

I am using a GridView and ListBox in a page. Gridview contains the data from db bind as DataSource. When clicking on an item in GridView the listbox displays the subitems.

My problem occurs when there is a scrollbar in GridView. When I select the last item from the gridview, the subitems are displayed and the scrollbar is going to up. I can't see which item is selected. Can any one give me a solution?

A: 

I suggest you reading the answers to the question http://stackoverflow.com/questions/616210/reset-scroll-position-after-async-postback-asp-net

Bogdan_Ch
A: 

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
A: 

I got the answer as

I place a hidden field as

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

and in div add a function

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

The javascrip is

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.

Sauron