Solved

GridView - Remember position of horizontal scrollbar on postback

Posted on 2008-11-01
5
1,968 Views
Last Modified: 2013-11-19
Hi
I have a gridview that is dynamically filled in - so don't know how many columns in design view.  
The columns need to be variable width - this is done in the Row_Created

   Dim td As TableCell
   For x = 1 To e.Row.Cells.Count - 1
     td = e.Row.Cells(x)
     td.Width = 70
   Next


I came to this after help on EE.


The horizontal scroll is displayed and user can navigate to right on gridview - gridview can't all be fitted on screen, maybe up to XXX columns.
The gridview column titles have link.  On clicking the link, there is a postback and values at top of screen are updated according to the column selected detailing all outputs in more user friendly way than a table.

The problem...
On postback, the horizontal position of scrollbar is forgotten. So the user could have scrolled well to the right off gridview to column 50 say, then on postback the horizontal scrollbar returns to left (column 1), and if the wanted detailed on column 51 they have to scroll all the way to right again.

So I want to maintain horizontal position of scrollbar if possible so user doesn't have to scroll all way to right again.
Had problems with AJAX on this page so don't want that route.

Thanks in advance
<asp:Panel ID="TablePanel" runat="server" Width="800px" Style="overflow: scroll;
     border: gray thin solid; border-width: 1px;" BorderColor="#FF6600">
     <div id="gridViewDiv" style="width: 5000px; background-color: Silver;">
         <asp:GridView ID="GridView1" runat="server" BackColor="white" GridLines="both" BorderStyle="Solid">
         </asp:GridView>
     </div>
</asp:Panel>

Open in new window

0
Comment
Question by:rwallacej
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
ID: 22856264
refer this link .. it will resolve your problem
http://forums.devx.com/showthread.php?t=154117
0
 

Author Comment

by:rwallacej
ID: 22856306
hi,
thanks for feedback.

I've taken the markup as Javascript from bottom of article (which seemed to be the solution), see below, but still don't retain positon.
I have put alert in the javascript to check it is called and it is.

can you advise further, please?
                <blockquote>
                    <div id="grdWithScroll" style="overflow:auto; width: 400px; background-color: Silver;" onscroll="SetDivPosition()">
                        <asp:GridView ID="GridView1" runat="server" BackColor="white" GridLines="both" BorderStyle="Solid">
                        </asp:GridView>
                    </div>
                </blockquote>
 
 
 
   <script type="text/javascript">
      window.onload = function(){
        var strCook = document.cookie;
        if(strCook.indexOf("!~")!=0){
          var intS = strCook.indexOf("!~");
          var intE = strCook.indexOf("~!");
          var strPos = strCook.substring(intS+2,intE);
          document.getElementById("grdWithScroll").scrollTop = strPos;
        }
      }
      
      function SetDivPosition(){
        var intY = document.getElementById("grdWithScroll").scrollTop;
        document.title = intY;
        document.cookie = "yPos=!~" + intY + "~!";
      }
    </script>

Open in new window

0
 

Author Comment

by:rwallacej
ID: 22856340
I should have put the code when it was changed to the position LEFT (I'm not bothered about vertical position). Here it is, but doesn't work
       window.onload = function(){
        var strCook = document.cookie;
        if(strCook.indexOf("!~")!=0){
            var intS = strCook.indexOf("!~");
            var intE = strCook.indexOf("~!");
            var strPos = strCook.substring(intS+2,intE);
            document.getElementById("grdWithScroll").scrollLeft = strPos;
        }
      }
      
      function SetDivPosition(){
        var intX = document.getElementById("grdWithScroll").scrollLeft;
        document.title = intX;
        document.cookie = "xPos=!~" + intX + "~!";
      }

Open in new window

0
 

Author Closing Comment

by:rwallacej
ID: 31512295
go it thanks.....needed to be the reference on my TablePanel not the DIV contained therein.
thank-you very much,
rwallacej
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22856978
your welcome
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Send parameters via datatable ajax call 4 40
Make Float not to Wrap 15 63
asp.net repeater server posting 5 35
display data from multiple ajax calls 9 35
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logiā€¦
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question