我正在通过 linq 搜索姓名和姓氏,我想将结果绑定到转发器。
我究竟做错了什么?
// this the results for list
public static List<SearchResults> lsSearchResults = new List<SearchResults>();
public class SearchResults
{
public string Name { get; set; }
public string Surname { get; set; }
public SearchResults(string name, string surname)
{
Name = name;
Surname = surname;
}
}
// search button
protected void btnSearch_Click(object sender, EventArgs e)
{
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();
}
}
private bool IsEmpty(object found)
{
throw new NotImplementedException();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
WAT THE HELL I PUT IN HERE ?? LOL for this ish to work
CLUELESS
}
这是转发器的 HTML 代码:
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text='<%#Eval("Name")%>'></asp:Label>
<asp:Label ID="Label5" runat="server" Text='<%#Eval("Surname")%>'></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</HeaderTemplate>
</asp:Repeater>