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>
有帮助吗?

解决方案

The Gridview should be inside the UpdatePanel as well.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top