2011-02-25 48 views
0

使用一个下拉列表和文本框,我需要在我的GridView中搜索数据。 假设我在下拉列表中选择1项并在文本框中输入一些文本。如何在gridview中搜索数据?

+1

在gridview的搜索数据△φ – 2011-02-25 09:00:44

+5

请详细说明您的问题。 – u449355 2011-02-25 09:09:59

+0

我认为标题是关于他的问题最有用的东西=) – 2012-10-03 11:08:49

回答

0

你应该写数据的apprpriate sql查询并重新绑定你的gridview。 或者你也可以过滤出已经绑定了gridview的dataser,其值为下拉框& textbox。

-1

我不知道,但:

string n = ""; 
int count = 0; 

if (RadioButton1.Checked == true) 
{ 
    ListBox3.Visible = true; 

    int x = GridView1.Rows.Count; 
    int o = GridView1.Columns.Count; 

    String SearchItem = TextBox1.Text; 
    for (int i = 0; i < x; i++) 
    { 
     for (int c = 0; c < o; c++) 
     { 
      if (SearchItem == GridView1.Rows[i].Cells[0].Text) 
      { 
       n = GridView1.Rows[i].Cells[1].Text + " R" + GridView1.Rows[i].Cells[5].Text; 
      } 
     } 
     ListBox3.Items.Add(n); 
    } 
} 
else if (RadioButton2.Checked == true) 
{ 
    ListBox3.Visible = true; 

    int x = GridView1.Rows.Count; 
    int o = GridView1.Columns.Count; 

    String SearchItem = TextBox1.Text; 
    for (int i = 0; i < x; i++) 
    { 
     for (int c = 0; c < o; c++) 
     { 
      if (SearchItem == GridView1.Rows[i].Cells[3].Text) 
      { 
       count++; 
       for (int a = 0; a < count; a++) 
       { 
        ListBox3.Items.Add(GridView1.Rows[i].Cells[1].Text + " R" + GridView1.Rows[i].Cells[5].Text); 
       } 
      } 
     } 
    } 
} 
+0

只有代码答案没有帮助 – 2012-10-03 11:06:47

0

是的,这很容易,如果您使用的是SQL数据源等,您只需要提filter expression和控件ID。因此,第一个控件(您的dropdownList)将包含名称,年龄,日期等过滤器值。文本框将包含搜索文本。像这样的过滤器表达式将意味着{0}为DropDownList值& {1}在文本框中的文本

CONVERT({0},'System.String') like '{1}%'