Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello,

I have seen several examples with a dropdownlist filtering the results in a
gridview.

Is there a way to have information typed in a text box used to filter a
gridview?

I would like to for example search on a persons first name and any first
name that contains the contents of my text box appear in the gridview list.


Regards
Karthikeyan
Posted
Comments
Toli Cuturicu 14-Mar-11 18:55pm    
DON'T SHOUT!!!

I would like to for example search on a persons first name and any first
name that contains the contents of my text box appear in the gridview list.

Whats in it? Go ahead and make one. All you need is to use the text of the texbox in the textchange event and filter the dataset using a dataview and then rebind the grid with the filtered dataview.

Try!
 
Share this answer
 
you need to add this code in the .aspx page

Collapse
<asp:Button ID="btnSearch" runat="server" Text="Click Me!"
onclick="btnSearch_Click" />



and you need to add this code in .aspx.cs page

protected void btnSearch_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(connstring);
string str = txtSearch.Text;
SqlCommand sqlcmd = new SqlCommand("select * from [table name] where fieldname like '%" + str + "%'", sqlcon);
SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataSet ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
lbl1.Visible = false;
gvActivities.DataSource = ds.Tables[0];
gvActivities.DataBind();
}
else
{
lbl1.Visible = true;
}
}
 
Share this answer
 
Comments
Ajay Kumar Tiwari From Mumbai 22-Mar-12 5:50am    
I want to search Gridview on Textbox text changing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900