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
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
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
RE: GridView row positioning after postback
this is why it gets a bit more tricky to do.