使用下拉列表和texboxs asp.net过滤gridview

时间:2016-07-05 10:37:10

标签: c# asp.net search gridview filter

我有一些dropdownliststextboxes。 我想通过gridviewdropdownlists按搜索按钮来过滤textboxes 我的代码适用于textbox,但不适用于dropdownlist 这是我的代码:

   GridView1.DataSource = g.getQuery("select * from MainData");
            string name = TextBox1.Text;
            string year = DropDownList6.SelectedItem.Text;
            string country = DropDownList1.Text.Trim();
            string right = DropDownList2.SelectedItem.Text.Trim();

            string pr = TextBox3.Text;
            string owner = DropDownList4.SelectedValue.ToString();
            string type = DropDownList5.Text;
            string f = "";
            if (name != "") { f = f + "[name] like '%" + name + "%' and "; }
            if (year != "") { f = f + "[year] like '% " +year + "%' and "; }
            if (country != "") { f = f + "country like '% " + country + "%' and "; }
            if (right != "") { f = f + "[right1] like '% " + right + "%' and "; }

            if (pr != "") { f = f + "[producter] like '% " + pr + "%' and "; }
            if (owner != "") { f =  f + "[owner] like '%"+ owner +"%' and "; }
            if (type != "") { f = f + "[bahre] like '% " + type+ "%' and "; }
                if (f.Length > 0)
            {
                string final = f.Remove(f.Length - 4 ,4);

            (GridView1.DataSource as DataTable).DefaultView.RowFilter = final;
                GridView1.DataBind();

            }
            else
            {
                GridView1.DataBind();
            }

任何帮助将不胜感激。

0 个答案:

没有答案