INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

GridView row positioning after postback

GridView row positioning after postback

(OP)
I've been struggling with this for 2 days now. How the heck do you handle scroll repositioning of a <div> after a postback of an ASP.NET web page?

I have a gridview inside a div. Scrolling through the gridview is actually being handled by scrolling through the div. Gridview controls don't have a scrollbar property.
Let's say that I scroll down to the 100th record of the gridview and click a button in there. I successfully handle the SelectedIndexChanged event and retrieve data from the gridview at that row.
Once the postback concludes, however, the position where I was in the div is lost and it positions itself at the top. That behavior is very annoying to the users because they have to manually scroll to the row they were at. Fortunately, I change the color scheme on the selected row so that can at least find where they were.

I've found dozens of developer forums where folks have posed this same question. Solutions range from java script to jquery. I've tried them and nothing works. All of the javascript solutions make reference to a scrollTop property for the div. That property doesn't even exist! I don't have access to jquery so wouldn't have any idea how to implement that.

My web page is embedded in a master page if this helps.

Does anyone have a solution for this problem?

Thanks in advance,
Jerry

Jerry Scannell

RE: GridView row positioning after postback

Quote:


All of the javascript solutions make reference to a scrollTop property for the div. That property doesn't even exist!
There is a property scrollTop which does not do any scrolling, you have to use animate to scroll the object.

Quote:


I don't have access to jquery so wouldn't have any idea how to implement that.
Everyone has access to JQuery. You just need to include a link to the CDN files or download the files and include them in your project. Using jquery you can use <element>.animate()
http://jquery.com/download/

You would have to trap the position of the div when the row is clicked and scroll to that position after postback. I am not saying it's going to be easy, but it can be done.
Why do you have a gridview in a scrollable div anyway? If you have a lot of rows, then use paging. This way on postback, the same page will be shown and the row highlighted and in view.

RE: GridView row positioning after postback

Isn't there a MaintainScrollPositionOnPostback="true" attribute you can just add to the page directive at the top of the master page to handle that?

RE: GridView row positioning after postback

There is but it only works in IE. Also, it will only scroll the page. He has the gridview inside of a scrollable div so the div needs to be scrolled not the page.
this is why it gets a bit more tricky to do.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close