在不查询数据库的情况下过滤gridview

时间:2015-11-25 08:13:20

标签: c# asp.net gridview

我尝试使用下拉列表中的所选项目过滤网格视图。使用sql查询很容易完成,但是如何在不查询数据库的情况下完成。例如,在下面的代码中。我按行业筛选。如果在DDL中选择的行业是"技术"我只想要技术行业的数据。 Industry是gridview中的列名。

   protected void Industry_Selected(object sender, EventArgs e)
    {

            string ddlItem = DropDownListFilterIndustry.SelectedItem.Text; //Get the dropdownlist value
            DataTable dt = ViewState["GridViewTable"] as DataTable; //get the viewstate of the gridview

            string[] columnNames = dt.Columns.Cast<DataColumn>() //get columns
                                 .Select(x => x.ColumnName)
                                 .ToArray();

            GridViewScreener.DataSource = dt;
            GridViewScreener.DataBind();
     }

0 个答案:

没有答案