hi... to all
i have created a webform in that form one gridview and above that one textbox is there.
i have connected to my database programatically..
now my question is when i type a text in the textbox and press enter button,
it should search in gridview only.. and again the data which searched had to display in sme gridview
Loading
Suthish NairPosted Feb 17, 2011, 2:12 PM
Amit ChoudharyPosted Feb 17, 2011, 1:15 AM
Write this code in the searchbutton click event.
IEnumerable
where e["Description"].ToString().Contains(srchTxt.Text)
select e;
lblMessage.Text = "Search result found: " + result.Count();
DataTable dtSearched = dt.Clone();
foreach(DataRow drow in result)
{
dtSearched.ImportRow(drow);
}
Bind the Grid to dtSerached datatable to show the results.
Thanks.
Amit ChoudharyPosted Feb 17, 2011, 1:00 AM
I found the easiest way of doing this:
for (int j = 0; j < GridView1.Rows.Count; j++)
{
for (int i = 0; i < GridView1.Columns.Count; i++)
{
if ( GridView1.Rows[j].Cells[i].Text.Contains("search criteria"))
{
GridView1.Rows[j].Cells[i].Visible = true;
break;
}
else
{
GridView1.Rows[j].Cells[i].Visible = false;
}
}
}
This will search the Grid in very efficient way..I'll post another solution that i have mentioned to you soon..
shashi reddyPosted Feb 16, 2011, 7:16 AM
give me .any example plz
Amit ChoudharyPosted Feb 16, 2011, 7:09 AM
Hope you got my point.