GridView in UpdatePanel paging

Dear experts,

I have an UpdatePanel and a GridView within it. I have a problem with paging: when I press Next button, grdUsers_PageIndexChanging() is not called, so the page stays 1, and if previously I changed selection in ddlPageSize, now it goes back to the initial selection.
Also, if I am on the first page, the Previous button is not disabled, and pressing it causes Out Of Range error.
What am I doing wrong?
Thanks.
<asp:UpdatePanel ID="upnlUsers" runat="server" ChildrenAsTriggers="true" UpdateMode="Always" >
        <ContentTemplate>
     
            <div style="height:400px; width:1500px; overflow:auto;">

            <asp:GridView ID="grdUsers" runat="server" AllowPaging="True" ShowHeader="false" ShowFooter="true" 
                AutoGenerateColumns="false" CssClass="largegridview largegridview_td" 
                Width="1480px" Height="100%" PageSize="100" DataKeyNames="ID" EnableSortingAndPagingCallbacks="false" 
                    onpageindexchanging="grdUsers_PageIndexChanging" 
                    onrowdatabound="grdUsers_RowDataBound">
                    <AlternatingRowStyle CssClass="alternatingrowstyle" />
                    
                    <Columns>
                         <asp:TemplateField HeaderText="User Name" SortExpression="Name">
                            <ItemTemplate>
                                <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Last Name" SortExpression="LastName">
                            <ItemTemplate>
                                <asp:Label ID="lblLastName" runat="server" Text='<%# Eval("LastName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                        
                        <asp:TemplateField HeaderText="First Name" SortExpression="FirstName">
                            <ItemTemplate>
                                <asp:Label ID="lblFirstName" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Email" SortExpression="Email">
                            <ItemTemplate>
                                <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                        
  
                    </Columns>

                    <PagerStyle CssClass="pagerstyle" />
                    <PagerTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Show rows:" />
                        <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true" 
                            OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
                            <asp:ListItem Value="20" />
                            <asp:ListItem Value="50" />
                            <asp:ListItem Value="100" />
                        </asp:DropDownList>
                        &nbsp;
                        Page 
                        <asp:TextBox ID="txtGoToPage" runat="server" AutoPostBack="true" 
                            OnTextChanged="GoToPage_TextChanged" CssClass="gotopage" />
                        of
                        <asp:Label ID="lblTotalNumberOfPages" runat="server" />
                        &nbsp;
                        <asp:Button ID="btnPrev" runat="server" CommandName="Page" 
                            ToolTip="Previous Page" CommandArgument="Prev" CssClass="previous" />
                        <asp:Button ID="btnNext" runat="server" CommandName="Page" ToolTip="Next Page" 
                            CommandArgument="Next" CssClass="next" />                  
                    </PagerTemplate>                      
                </asp:GridView>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

Open in new window

tantormediaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
give this a try:

Protected Sub grdUsers_PageIndexChanging(...) Handles gvEvents.PageIndexChanging            

     gvEvents.PageIndex = e.NewPageIndex
     LoadData() //you must reload the data and rebind the grdiview
     gvEvents.DataBind()
   
     AJAXPanel.Update()  // The below line refreshes the update panel..  

end sub

also check if the page is posting back at all when you click to move onto another page (maybe just put a breakpoint on the Page_Load method or something AND also on grdUsers_PageIndexChanging).
0
tantormediaAuthor Commented:
Thank you for your answer.
But what is "LoadData()"? Other than that, I do everything like you wrote, but the problem is that this event handler is not called at all, as I wrote above.
0
Kaushal AroraTechnical AnalystCommented:
LoadData means you need to rebind your gridview with the data you are binding with.
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

tantormediaAuthor Commented:
So as I said, I did what you said without success.
0
Kaushal AroraTechnical AnalystCommented:
You are giving CommandName="Next" or "Prev" so it will never call the PageINdexChanging event.

Refer to this article for the details about the custom paging as you are doing.

http://www.codeproject.com/KB/grid/GridView_pager.aspx

Hope it helps you.
0
MlandaTCommented:
I'm not so sure KaushalArora. Microsoft says (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pagertemplate.aspx)

Typically, button controls are added to the pager template to perform the paging operations. The GridView control performs a paging operation when a button control with its CommandName property set to "Page" is clicked. The button's CommandArgument property determines the type of paging operation to perform. The following table lists the command argument values supported by the GridView control.
0
Kaushal AroraTechnical AnalystCommented:
Thanks MlandaT.

I misread the html for CommandArgument to CommandName.

But still http://www.codeproject.com/KB/grid/GridView_pager.aspx will be helpful for the tantormedia.

Thanks once again.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.