开发者

How to search data in gridview?

Using one Dropdownlist and textbox, I need to search data in my gridvi开发者_JAVA技巧ew. Suppose I select 1 item in the dropdownlist and enter some text in the textbox.


You sould write to apprpriate sql query against data and rebind your gridview. Or you can filter out dataser which is already bound with gridview with value of dropdown & textbox.


Yes, that is easy if you are using a SQL Datasource etc. You just need to mention a filter expression and control ids. So, the first control (your dropdownList) would contain filter values like Name,Age,Date etc. The textbox would contain search text. A filter expression like this would mean {0} for the dropdownlist value & {1} for the textbox text

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


I am not sure, but:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜