If this is for an SPGridView then you can do two techniques!
One is to use the filtering option:
http://www.reversealchemy.net/blog/2009/05/24/building-a-spgridview-control-part-2-filtering/
or the second is to make a custom control within the webpart(if it is that) that contains the creation of SPGridview and databinding.
Have a textbox added to the controls first with a button, then add the SPGridview. When the user searches on the textbox and clicks the button it triggers a clickevent for the button that gets the dataview to get the results but this time it has a new feild that contains the textbox.text instead.... and rebind the result to the gridview. So it would look somthing like this:
void searchButton_Click(object sender, EventArgs e)
{
dvUsers = new DataView(DataAccess.GetList(_IDClient, _IDScheme), searchBoxFilter.Text));
gridView.AutoGenerateColumns = false;
gridView.DataSource = dvUsers;
gridView.PagerTemplate = null;
gridView.DataBind();
searchBoxFilter.Focus();
}
I would suggest using the filter or if you want use the second method if you want it custom made. The second mthod works as i have done it and it returns just the searched query that you want to use.
here are some other ways:
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/ead1e4bb-92cd-4062-93de-284868849bed/
also this:
Querying items in a SharePoint List
http://clintoncherry.wordpress.com/2007/10/15/querying-items-in-a-sharepoint-list/
Hope it helps :)