网格视图 ASP.Net 中的分页不起作用

问题描述 投票:0回答:1

我有一个使用 C# 的 ASPX 应用程序。在页面中,我有一个带分页的 gridview(我添加allowpaging =“true”,PageSize =“2”)。 在 aspx 文件中:

  <table>
    <tr>
        <td>
            <asp:GridView ID="grdClientList" runat="server" OnRowCreated="grdClientList_RowCreated"
                OnRowDataBound="grdClientList_RowDataBound" AutoGenerateColumns="False" 
                DataSourceID="ODSClientList" DataKeyNames="ID"
                AllowPaging="true" AllowSorting="true" PageSize="2"
                OnPageIndexChanging="grdClientList_PageIndexChanging">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" 
                        ItemStyle-CssClass="hidden"  HeaderStyle-CssClass="hidden" />
                    <asp:BoundField DataField="Name" HeaderText="<%$Resources:HRWebApplicationResources,ClientsList_ColName %>" SortExpression="Name" 
                         ControlStyle-Width="150px" ItemStyle-Width="150px"/>
                    <asp:BoundField DataField="Address" HeaderText="<%$Resources:HRWebApplicationResources,ClientsList_ColAddress %>" SortExpression="Address" 
                        ControlStyle-Width="280px" ItemStyle-Width="280px"/>
                    <asp:BoundField DataField="Contact" HeaderText="<%$Resources:HRWebApplicationResources,ClientsList_ColContact %>" SortExpression="Contact"
                         ControlStyle-Width="100px" ItemStyle-Width="100px"  />
                    <asp:BoundField DataField="Telephone" HeaderText="<%$Resources:HRWebApplicationResources,ClientsList_ColTelephone %>" SortExpression="Telephone" 
                         ControlStyle-Width="100px" ItemStyle-Width="100px" />
                    <asp:BoundField DataField="Email" HeaderText="<%$Resources:HRWebApplicationResources,ClientsList_ColEmail %>" SortExpression="Email" 
                        ControlStyle-Width="130px" ItemStyle-Width="130px" />
                    <asp:HyperLinkField 
                          HeaderText="<%$Resources:HRWebApplicationResources,AllPages_Actions%>" ShowHeader="True" Text="Edit"
                          DataNavigateUrlFormatString="~/Client/ClientDetail.aspx?Id={0}" 
                          DataNavigateUrlFields="ID" ControlStyle-Width="70px" ItemStyle-Width="70px"/>
                </Columns>
            </asp:GridView>
        </td>
    </tr>
</table>

 <asp:ObjectDataSource ID="ODSClientList" runat="server" OldValuesParameterFormatString="{0}"
    SelectMethod="GetAllClientsByFilter" TypeName="HRWebApplication.AppCode.ManageList">
    <SelectParameters>
       <asp:ControlParameter ControlID="txtSearchName" Name="p_strName" PropertyName="Text" Type="String" />
       <asp:ControlParameter ControlID="txtSearchAddress" Name="p_strAddress" PropertyName="Text" Type="String" />
       <asp:ControlParameter ControlID="txtSearchContact" Name="p_strContact" PropertyName="Text" Type="String" />
       <asp:ControlParameter ControlID="txtSearchTelephone" Name="p_strTelephone" PropertyName="Text" Type="String" />
       <asp:ControlParameter ControlID="txtSearchEmail" Name="p_strEmail" PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

在cs文件中:

  protected void grdClientList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdClientList.PageIndex = e.NewPageIndex;
        grdClientList.DataBind();
    }

当我单击第二个、第三个等页面时,我的应用程序不执行任何操作。不进入“grdClientList_PageIndexChanging”事件。有人知道为什么吗?

c# asp.net pagination page-index-changed
1个回答
0
投票

也许尝试使用 PageIndexChanged 而不是 PageIndexChanging?

© www.soinside.com 2019 - 2024. All rights reserved.