I have a gridView
<asp:GridView ID="InGridView" PageSize="5" AllowPaging="true" runat="server" OnPageIndexChanging="InGridView_PageIndexChanging" ></asp:GridView>
code binding to grid.
private void LoadGridView(string filename)
{
invTable = new DataTable();
// gets data from uploaded csv file
DataTable csvDatatable=GetdataFromCSV(string filename)
// Code to populate invTable with the data..
invTable= checkCsvandGetTable(csvDatatable)
InGridView.DataSouce = invTable;
inGridView.DataBind();
} where data binding is being done on button_click and datasource is datatable which i am generating from csv file.
how to allow paging in such scenario
the invTable is null when i am selecting 2 page for first page its working fine.
any idea on this?
You need to load invTable with the data again and bind it to the GridView in PageIndexChanged event.
Let say you have a method which creates a datatable, populates it with data and binds it to the gridview. And you are calling this method from the button click.
private void LoadGridView()
{
invTable = new DataTable();
// Code to populate invTable with the data..
InGridView.DataSouce = invTable;
inGridView.DataBind();
}
You need to call the same method from the PageIndexChanged event handler.
So, PageIndexChanged eventhandler of InGridView should be written as following.
protected void InGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
InGridView.PageIndex = e.NewPageIndex;
LoadGridView();
}
This should resolve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With