【问题标题】:Paging in a gridview ASP.Net doesn't workgridview ASP.Net 中的分页不起作用
【发布时间】:2013-01-30 13:27:59
【问题描述】:

我有一个带有 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 paging page-index-changed


【解决方案1】:

也许试试 PageIndexChanged 而不是 PageIndexChanging?

【讨论】:

    猜你喜欢
    • 2011-06-15
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    相关资源
    最近更新 更多