伙计们,我有两个问题......首先我有一个 linq 查询搜索,它查询姓名和姓氏并从数据库返回结果。例如,如果我搜索 John,它将返回完美的 John travolta(我的问题是)如果我同时搜索 john travolta 的名字和姓氏,它会找不到结果?...帮助。
问题二:再次搜索时如何清除搜索结果?因为当我第二次搜索时,前一次搜索的结果是
public class SearchResults
{
public string Name { get; set; }
public string Surname { get; set; }
public SearchResults(string name, string surname)
{
Name = name;
Surname = surname;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string search = txtSearch.Text.ToLower().TrimEnd();
lsSearchResults = null;
lsSearchResults = new List<SearchResults>();
Repeater1.DataSource = null;
lsSearchResults.Clear();
Repeater1.DataSource = "";
}
if (string.IsNullOrWhiteSpace(txtSearch.Text))
{
lblResults.Text = "Please enter a password & Em@ilAddress";
lsSearchResults.Clear();
return;
}
else
{
var found = (from User in myDB.Memberships
where User.Name.ToLower().Contains(txtSearch.Text.ToLower()) ||
User.Surname.ToLower().Contains(txtSearch.Text.ToLower())
select new { User.Name, User.Surname });
// validates items in search query if Exist
if (!ChillZARdev.App_Code.Utilities.IsEmpty(found))
{
foreach (var user in found)
{
lsSearchResults.Add(new SearchResults(user.Name, user.Surname));
// ls.Add(user.Name + " " + user.Surname);
// Response.Write(user);
}
Repeater1.DataSource = lsSearchResults;
Repeater1.DataBind();
}
}