I have paging in my GridView, and it worked nicely before: it was filtering by a “user key” value in a TextBox. However, since I added filtering to my GridView, the paging has some problems. When the user tries to click page 2, it will show page 2 of the GridView before it was filtered.
Can someone help me? Below is my paging code-behind:
protected void gvPaging(object sender, GridViewPageEventArgs e)
{
DefaultData();
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
filtering code:
protected void Button1_Command(object sender, EventArgs e)
{
string folderName = ConfigurationManager.AppSettings["folderPDF"].ToString();
string path = Server.MapPath("./");
string fpaths = path + folderName;
string[] filePath = Directory.GetFiles(fpaths, "*.pdf");
DataTable table = GetTable(filePath);
//var dataTable = (DataTable)GridView1.DataSource;
var dataView = table.DefaultView;
dataView.RowFilter = "folderName LIKE '" + DocSearch.Text.Trim() + "%'";
GridView1.DataSource = table;
GridView1.DataBind();
DocSearch.Text = "";
}
DefaultData()
public void DefaultData()
{
string folderName = ConfigurationManager.AppSettings["folderPDF"].ToString();
string path = Server.MapPath("./");
string fullPath = path + folderName;
string[] filePaths = Directory.GetFiles(fullPath, "*.pdf");
DataTable table = GetTable(filePaths);
GridView1.DataSource = table;
GridView1.DataBind();
}
You need to add the filterig option into the the grid view paging function or it will not work, since you need to tell it from what data source it should fetch the information