分页&在Gridview Unser UpdatePanel中排序无效

时间:2014-05-15 09:51:37

标签: c# sorting gridview updatepanel paging

分页排序在“更新”面板

下无效
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="True">
   <ContentTemplate>
       <asp:GridView ID="gvInvoiceList" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-hover" EnableSortingAndPagingCallbacks ="false" AllowPaging="True" OnRowCommand="gvPrograms_RowCommand" AllowSorting="True" PageSize="5">
             <Columns>
                  <asp:BoundField DataField="InvoiceID" HeaderText="Invoice ID" SortExpression="InvoiceID" />
                  <asp:BoundField DataField="FID" HeaderText="Franchise ID" SortExpression="FID" />
                  <asp:BoundField DataField="CID" HeaderText="Kid ID" SortExpression="CID" />
                  <asp:BoundField DataField="Datecreated" HeaderText="Date Generated" SortExpression="Datecreated" />
                  <asp:TemplateField>
                         <ItemTemplate>
                            <asp:LinkButton runat="server" ID="btnView"  CommandName="View" CssClass="btn blue" CommandArgument='<%# Eval("InvoiceID") %>' Text="View"></asp:LinkButton>
                         </ItemTemplate>
                  </asp:TemplateField>
            </Columns>
       </asp:GridView>
       <asp:SqlDataSource ID="DSInvoiceMaster" runat="server" ConnectionString="<%$ ConnectionStrings:ThinkTapDBConnectionString %>" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT DISTINCT [FID], [CID], [Datecreated], [InvoiceID] FROM [InvoiceMaster] ORDER BY [InvoiceID] DESC"></asp:SqlDataSource>
   </ContentTemplate>
   <Triggers>
         <asp:AsyncPostBackTrigger ControlID="txtSearch" EventName="TextChanged" />
         <%-- <asp:AsyncPostBackTrigger ControlID="gvInvoiceList" EventName="RowCommand" />--%>
         <%--<asp:AsyncPostBackTrigger ControlID="gvInvoiceList" EventName="PageIndexChanging" />--%>
    </Triggers>
</asp:UpdatePanel>

请帮助 感谢

1 个答案:

答案 0 :(得分:1)

要在asp.net Paging中添加gridview,您必须处理OnPageIndexChanging事件:

<强>标记

<asp:GridView ID="gvInvoiceList" 
              DataSourceID="DSInvoiceMaster" 
              AutoGenerateColumns="false"
              CssClass="table table-striped table-hover" 
              EnableSortingAndPagingCallbacks ="false" 
              AllowPaging="True" 
              AllowSorting="True" 
              PageSize="5"
              OnRowCommand="gvPrograms_RowCommand"
              OnPageIndexChanging="gvInvoiceList_PageIndexChanging"  
              runat="server">

代码

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

MSDN example on GridView.OnPageIndexChanging Event

对于Sorting,您有跟踪OnSorting gridview事件。

MSDN example reference on GridView.Sorting event
以下是示例reference

更新:您尚未在此处指定gridview datasourceid。请参阅更新的标记。