I am trying to fix a search tool for work. This is the first time I have encountered ASP.NET. The current search tool has a radio Button list with three options of how to search our local directory. However the person that worked on this project before me did not finish the code and has since quit. The radio buttons as they are not do not affect the search query as I have noticed that no matter what option you pick the query is the same.
This is my attempt to rewrite the search function to incorporate the three radio button options. However when I incorporate this function into the rest of the code the page does not render at all and I am not getting the error. I dont think I made an error in the query strings because I took the original one and made variations of it by omitting Contains statements. I'm assuming the error comes from my if statements or how I am trying to compare the asp.net RadioButtonList ListItem values.
protected void btnclick_WorkspaceSearch(object sender, EventArgs e){
string strSearchTerm=tbSearch.Text.Trim()
if (rblSearchOption.SelectedValue == "all"){
// Find the search term in either a file name or file content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "OR CONTAINS(Contents, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue=="names"){
// Find the search term in a file name
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue =="contents") {
// Find the search term in a file's content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
searchIndex(indexQuery);
lit_strQueryString.Text = indexQuery;
}
I figured out the problem. For those that commented thank you for your input I did make some necessary changes to help correct potential errors. As for the original question to compare listItem values the line that I used was :
if (rblSearchOption.SelectedItem.Value =="contents"){
//logic here
}
i had tried this before but it did not work. I'm assuming because of the errors pointed out in the comments.
Additional Notes(based on the comments): The code above has a missing ; in line1
string index query should be declared and initiated outside of the if statements.
Once again thank you to those who attempted to help me.