我正在尝试修复一项工作中的搜索工具。这是我第一次遇到ASP.NET。当前的搜索工具有一个单选按钮列表,其中包含三个选项,用于搜索我们的本地目录。然而,在我之前参与该项目的人没有完成代码并已经离职了。正如我注意到的那样,无论您选择哪个选项,单选按钮都不会影响搜索查询,因为查询总是相同的。
这是我试图重写搜索函数以纳入三个单选按钮选项的尝试。然而,当我将此功能合并到其余代码中时,页面根本没有呈现,并且我没有得到错误消息。我认为我没有在查询字符串中犯错误,因为我采用了原始查询字符串并通过省略Contains语句来进行变化。我假设错误来自我的if语句或我尝试比较ASP.NET RadioButtonList ListItem值的方式。
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;
}
searchIndex(indexQuery);
并说“导航到定义”时,indexQuery
在哪里定义?这三个indexQuery
变量在if
语句中具有局部作用域,因此无法在外部作用域(整个方法)中使用。此外,第一行末尾缺少一个;
。你是从实际的工作代码库中复制/粘贴的吗? - mellamokb