【发布时间】:2011-02-25 08:59:55
【问题描述】:
使用一个下拉列表和文本框,我需要在我的网格视图中搜索数据。 假设我在下拉列表中选择了一项并在文本框中输入了一些文本。
【问题讨论】:
-
请详细说明您的问题。
-
我认为标题对他的问题最有帮助=)
使用一个下拉列表和文本框,我需要在我的网格视图中搜索数据。 假设我在下拉列表中选择了一项并在文本框中输入了一些文本。
【问题讨论】:
您应该针对数据编写适当的 sql 查询并重新绑定您的网格视图。 或者您可以过滤掉已经与 gridview 绑定的 dataser,其值为下拉列表和文本框。
【讨论】:
是的,如果您使用 SQL 数据源等,这很容易。您只需要提及 filter expression 和控制 ID。因此,第一个控件(您的下拉列表)将包含过滤器值,例如名称、年龄、日期等。文本框将包含搜索文本。像这样的过滤器表达式意味着下拉列表值的 {0} 和文本框文本的 {1}
CONVERT({0},'System.String') like '{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);
}
}
}
}
}
【讨论】: