Question

Paging sorting not works under Update panel

<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>

Plese Help thanks

Était-ce utile?

La solution

For adding Paging in asp.net gridview you have to handle OnPageIndexChanging event:

Markup:

<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">

Code behind:

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

MSDN example on GridView.OnPageIndexChanging Event.

For Sorting you have track OnSorting event of gridview.

MSDN example reference on GridView.Sorting event.
Here is example reference.

UPDATE: you have not specified datasourceid of gridview here. See updated markup.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top