i have a datset that i save into viewstate and i want to paging on that dataset.

Code for bind gridview

DataSet _ds = _fOrderInvoice.ExecuteDataSet();
ViewState["FIOrders"] = _ds.Tables[0];
grdInvoiced.DataSource = _ds;  // bind the gridview 

Now i want paging on the gridview. So how can i do that from the dataset that i have save into my ViewState["FIOrders"]. My gridview is below

     <asp:GridView  ID="grdInvoiced" runat="server" Width="100%" ViewStateMode="Enabled"  DefaultSortColumnName="OrderNo"                                        OnSelectedIndexChanged="GridInvoice_SelectedIndexChanged" AutoGenerateColumns="False" OnSorting="invoice_sorting" OnRowDataBound="grdInvoice_Rowdatabount" ShowFooter="true" PageSize="20" AllowPaging="True" AllowSorting="True" DataKeyNames="OrderNo" ExcelExportFileName="Export_AccountTerms.xls"
 ShowHeaderWhenEmpty="true" OnPageIndexChanging="grdInvoiced_PageIndexChanging">
 <Columns>
    <asp:CommandField ShowSelectButton="True" SelectText="View" />
        <asp:TemplateField>
          <ItemTemplate>
         <asp:CheckBox ID="rbtnSelect" GroupName="a" runat="server" />
         <asp:Literal ID="ltOrder" runat="server" Text='<%# Eval("OrderNo")%>' Visible="false"></asp:Literal>
         </ItemTemplate>
       <HeaderStyle HorizontalAlign="Left" Width="50px" />
     </asp:TemplateField>    
     </Columns>    
    </asp:GridView>

PageIndexChanging event

protected void grdInvoiced_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdInvoiced.PageIndex = e.NewPageIndex+1;
        if (ViewState["FOrders"] != null)
        {
            Collection<FinalizedOrderInvoiceRows> _rows = ViewState["FIOrders"] as Collection<FinalizedOrderInvoiceRows>;
            grdInvoiced.DataSource = _rows;
            grdInvoiced.DataBind();
        }

    }

Related posts

Recent Viewed