如何过滤数据集并在gridview中绑定 [英] how to filter the dataset and bind in the gridview
本文介绍了如何过滤数据集并在gridview中绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想过滤数据集中的数据,并在Gridview中显示该数据.
i want to filter the data in dataset and that data display in gridview.
推荐答案
尝试一下
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=test;Integrated Security=True");
string statment = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt from Items ";
SqlDataAdapter da = new SqlDataAdapter(statment, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow[] foundRows = ds.Tables[0].Select("item_code = 1", " item_code DESC", DataViewRowState.CurrentRows);
//this is for create datatable with same schema like the orginal one .
string statment2 = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt from Items where item_code = 0";
SqlDataAdapter da2 = new SqlDataAdapter(statment2, con);
DataTable dt = new DataTable();
da2.Fill(dt);
DataRow dr = dt.NewRow();
foreach (DataRow row in foundRows)
{
dr[0] = row[0];
dr[1] = row[1];
dr[2] = row[2];
dr[3] = row[3];
dr[4] = row[4];
dr[5] = row[5];
dt.Rows.Add(dr);
}
con.Close();
cmd.Dispose();
GridView1.DataSource = dt;
GridView1.DataBind();
}
只需在 Google 上搜索它 [ ]
你会得到结果的.
Hi,
just Search It On Google[]
U Will Get Ton Of Results.
我认为这些代码项目文章可能会有所帮助
具有分页和过滤功能的自定义GridView [ GridView全部集成 [
I think these Code Project articles may be helpful
Custom GridView with Paging and Filtering[^]
GridView all in one[^]
这篇关于如何过滤数据集并在gridview中绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文