使用过滤器在Gridview中搜索 [英] Search in Gridview with filters

查看:74
本文介绍了使用过滤器在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]
Maintain projectCode and projectName also in the table and just display the projectName in Grid and use the respective value of projectCode to search.



Corrected formatting issues.
[/Edit]


试试这个。希望它会对你有所帮助。



txtName 是搜索 TextBox ddlSearch DropDownList 用于过滤

Try this. Hope it will help you.

txtName is the search TextBox and ddlSearch is DropDownList 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆