If this is for an SPGridView then you can do two techniques!
One is to use the filtering option:
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;
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:
Querying items in a SharePoint List
Hope it helps :)