我在我的 GridView 中进行了分页,它以前运行良好:它是通过 TextBox 中的“用户键”值进行过滤的。但是,由于我在 GridView 中添加了过滤,因此分页存在一些问题。当用户尝试点击第 2 页时,它会显示 GridView 在被过滤之前的第 2 页。
有人能帮我吗?下面是我的分页代码隐藏:
protected void gvPaging(object sender, GridViewPageEventArgs e)
{
DefaultData();
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
过滤代码:
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 = "";
}
默认数据()
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();
}