使用过滤器在Gridview中搜索 [英] Search in Gridview with filters
本文介绍了使用过滤器在Gridview中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的'Table1'SQL表中,我有'ProjectCode',它取自Master Table。我将'Table1'附加到gridview。在该表中,我显示'ProjectName'而不是'ProjectCode'。但是在项目名称上我无法搜索记录。
Hi,
In my 'Table1' SQL table I have 'ProjectCode' which is taken from Master Table. I am attaching 'Table1' to gridview. In that table I am displaying 'ProjectName' instead of 'ProjectCode'. But on Project Name I cannot search the records.
推荐答案
维护projectCode
和projectName
也在表格中,只在Grid
中显示projectName
并使用相应的值projectCode
进行搜索。
更正格式问题。
[/ Edit]
MaintainprojectCode
andprojectName
also in the table and just display theprojectName
inGrid
and use the respective value ofprojectCode
to search.
Corrected formatting issues.
[/Edit]
试试这个。希望它会对你有所帮助。
txtName
是搜索TextBox
和ddlSearch
是DropDownList
用于过滤
Try this. Hope it will help you.
txtName
is the searchTextBox
andddlSearch
isDropDownList
for filtering
private void txtName_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Connection.getConnectionString());
if (ddlSearch.Text == "Enter Name")
{
con.Open();
SqlDataAdapter adap = new SqlDataAdapter("select * from Item where Item_name like '" + txtName.Text + "%'", con);
SqlCommandBuilder build = new SqlCommandBuilder(adap);
DataSet ds = new DataSet();
adap.Fill(ds, "Items");
dataGridView1.DataSource = ds.Tables["Items"];
con.Close();
}
if (ddlSearch.Text == "Enter Item Code")
{
con.Open();
SqlDataAdapter adap = new SqlDataAdapter("select * from Item where Item_code like '" + txtName.Text + "%'", con);
SqlCommandBuilder build = new SqlCommandBuilder(adap);
DataSet ds = new DataSet();
adap.Fill(ds, "Items");
dataGridView1.DataSource = ds.Tables["Items"];
con.Close();
}
}
更正了格式和语法问题。
[/编辑]
这篇关于使用过滤器在Gridview中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文