将过滤器应用于数据集时,不在gridview中显示数据

时间:2012-01-17 07:18:27

标签: asp.net .net gridview filter dataset

我的gridview在过滤时没有显示数据

protected void Page_Load(object sender, EventArgs e)
    {
        OleDbConnection conn=new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Dynacs.accdb");
        OleDbDataAdapter da = new OleDbDataAdapter("select empname,pass,status from employees", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "emp");
        GridView1.DataSource = ds.Tables["emp"].Select("status='in'");
        GridView1.DataBind();
    }


Showing this when executed

1 个答案:

答案 0 :(得分:0)

OleDbDataAdapter da = new OleDbDataAdapter("select empname,pass,status from employees", conn);
        DataSet ds1=new DataSet();
        da.Fill(ds1,"emp");
            var datasource = from r in ds1.Tables["emp"].AsEnumerable()
                             where r.Field<string>("status")=="out"
                             select new{empname=r.Field<String>("empname"),status=r.Field<string>("status")};
            GridView1.DataSource = datasource;
            GridView1.DataBind();