0

我在我的 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();
}
4

2 回答 2

0

您需要将 filterig 选项添加到网格视图分页功能中,否则它将不起作用,因为您需要告诉它应该从哪个数据源获取信息

于 2012-05-07T07:48:08.353 回答
0

真的我为这个问题搜索了很多,人们正在寻找我在这里找到的正确解决方案..嘿..首先enablepagingandcallback = false在 gridview 中设置,然后添加

Private Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    GridView1.PageIndex = e.NewPageIndex
    GridView1.DataSource = SqlDataSource1
    GridView1.DataBind()

End Sub

如果使用 dataview 过滤器,这就是全部,使用它而不是 sqldatasource 过滤表达式

于 2013-08-08T19:42:50.927 回答