Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Maintain page in Gridview on postback inside an Update Panel.

Posted on 2014-03-03
3
Medium Priority
?
376 Views
Last Modified: 2014-03-11
I have a gridview that has several pages in it.  The problem is that if I am on page 4 and then do an edit and cancel, it goes back to page 1.  I have tried doing some javascript to maintain the position and the maintainscrollpositiononPostback, but nothing seems to work.

I used the following javascript
<script type="text/javascript">
        $(document).ready(function () {
            var xPos, yPos;
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_beginRequest(BeginRequestHandler);
            prm.add_endRequest(EndRequestHandler);

            function BeginRequestHandler(sender, args) {
               
                //Get X and Y positions of scrollbar before the partical postback
                xPos = $get('scrollWork').scrollLeft;
                yPos = $get('scrollWork').scrollTop;

            }


            function EndRequestHandler(sender, args) {
               
                //Set X and Y positions back to the scrollbar after the partial postack
                $get('scrollWork').scrollLeft = xPos;
                $get('scrollWork').scrollTop = yPos;
            }
        });
       

    </script>

My page looks like this:

<asp:UpdatePanel runat="server" ID="UpdatePanel2"
    >
    <ContentTemplate>      
    <div id="scrollWork" > 
<asp:GridView ID="WorkOrderGrid" runat="server" AutoGenerateColumns="False"
        AllowPaging="True" AllowSorting="True" DataKeyNames="Task_id"
         
        OnSorting="WorkOrderGrid_Sorting"
        OnSelectedIndexChanged="WorkOrderGrid_SelectedIndexChanged" Width="1042px"
            ondatabound="WorkOrderGrid_DataBound"
            onpageindexchanging="WorkOrderGrid_PageIndexChanging"
            onrowdatabound="WorkOrderGrid_RowDataBound" >
 <Columns>
 <asp:BoundField DataField="Task_id" HeaderText = "No." SortExpression="Task_id" />
 <asp:BoundField DataField="CatName" HeaderText="Problem Area" SortExpression="CatName" />
     <asp:TemplateField HeaderText="Problem">
         <EditItemTemplate>
             <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TaskDescription") %>'></asp:TextBox>
         </EditItemTemplate>
         <ItemTemplate>
             <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("TaskDescription") %>'></asp:Label>
         </ItemTemplate>
     </asp:TemplateField>
 <asp:BoundField DataField= "TaskRequestDate" HeaderText = "Request Date" SortExpression="TaskRequestDate" />
 <asp:BoundField DataField = "TaskRequestedBy" HeaderText = "Requestor" SortExpression="TaskRequestedBy" />
 <asp:BoundField DataField="RoomNo" HeaderText="Room" SortExpression="RoomNo" />
 <asp:BoundField DataField="Phone" HeaderText="Phone"/>
 <asp:BoundField DataField = "TaskAssignedTo" HeaderText = "Assigned To" SortExpression="TaskAssignedTo" />
 <asp:BoundField DataField = "Status_Description" HeaderText = "Status" SortExpression="Status_Description" />
     <asp:ButtonField CommandName="Select" Text="Select" />
 
 </Columns>
    <FooterStyle CssClass="GridFooter" />
 </asp:GridView>
 </div>
 </ContentTemplate>
            </asp:UpdatePanel>
0
Comment
Question by:Dukster131
[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
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
apeter earned 1500 total points
ID: 39903105
Don't you have to store the position while leaving the page and restore them when you come back from page 4 ?
0
 
LVL 1

Author Comment

by:Dukster131
ID: 39903258
I am never leaving the page - just making gridview visible and invisible and Panels visible and invisible.
0
 
LVL 1

Author Comment

by:Dukster131
ID: 39920808
I tried saving the newPageIndex in a session variable and using that when I cancelled the details view.  Then when I got the data I used

if (Session["Page"] != null)
                    {
                        WorkOrderGrid.PageIndex = Convert.ToInt32(Session["Page"]);
                    }
                    else
                    {
                        WorkOrderGrid.PageIndex = newPageIndex;
                    }

That worked.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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