I am trying to create a web part which contains a custom search box to query a list. The list is contained in the same site as the search. I have tried to create a search query using either CAML or SQL syntax without success. The current code attachment uses CAML.
The list is named "_Customer".
The search box is named "txtSearchBox"
If I execute the search without trying to query the specific list name I get a returned results from the entire collection in the DataTable. While this is good that I get a returned results it does not get me the specific targeted list results.
The attached image is two separate images combined together. The purple dotted line segment is the search box. The red dotted line is the "_Customer" list. The returned result DataTable actually is supposed to be displayed underneath the search web part. As you can see from this image it has not been included since it is empty. For clarification we changed the default "Title" column to be renamed to "Account Name" in the "_Customer" list.
What is wrong with the code? What happens now is when a search is done the page refreshes and returns nothing. By this I mean there is no error and the page renders normally as if the search was not performed. During postback it appears the browser thought for a few moments as if it might return a DataTable of results, but when the page comes back there are no results.
My end game is to create a dynamic search criteria using multiple search boxes to query a list or multiple lists for a robust result set. Some of the field names we will be targeting would include: name, phone, zip, account, id, etc.
public partial class SearchUserControl : UserControl
protected Button btnSearch;
protected TextBox txtSearchBox;
protected Label lblResults;
protected GridView gridSearchResults;
protected override void CreateChildControls()
txtSearchBox = new TextBox();
lblResults = new Label();
btnSearch = new Button();
btnSearch.Text = "Find";
btnSearch.Click += new EventHandler(btnSearch_Click);
void btnSearch_Click(object sender, EventArgs e)
lblResults.Text = "Please enter words to search for";
void ExecuteKeywordQuery(string keywordQueryText)
string searchword = txtSearchBox.Text;
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope='Recursive'";
SPList list = SPContext.Current.Web.Lists["_Customer"];
query.Query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>searchword</Value></Eq></Where>");
//SPListItem item = list.GetItems(query);
if (list.Items.Count > 0)
DataTable result = new DataTable();
result.TableName = "SearchResults";
private void PopulateResultsGrid(DataTable resultsTable)
gridSearchResults = new GridView();
gridSearchResults.DataSource = resultsTable;
protected override void Render(HtmlTextWriter writer)
if (gridSearchResults != null)