The Gridview should be inside the UpdatePanel as well.
GridView paging callbacks stop working after UpdatePanel postback
-
22-07-2023 - |
Question
I have a paged GridView with EnableSortingAndPagingCallbacks enabled and AutoGenerateColumns disabled. The GridView paging works fine on the initial page load, but if I trigger an UpdatePanel PostBack by using the DropDownList, the GridView paging stops working.
Here's a stepthrough of what happens:
- Initial page load
- Click "2" at bottom of GridView. Page 2 loads
- Change dropdown selection to "Item 2"
- Click "3" at bottom of GridView. Nothing happens
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test_script.aspx.cs" Inherits="test_script" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<form runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true">
<asp:ListItem Text="Item 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Item 2" Value="2"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<br /><br />
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" AllowPaging="true"
EnableSortingAndPagingCallbacks="true" AutoGenerateColumns="false"
DataSourceID="dsStudents">
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsStudents" runat="server" ConnectionString="xxx"
SelectCommand="SELECT ID, name from students" />
</form>
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow