我正在通過linq搜索姓名,我想將結果綁定到中繼器。如何將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>
有什麼問題?你有編譯器錯誤嗎?一個例外?有什麼問題,先! –
什麼不起作用?!?!?如果你不告訴我們什麼不工作,我們應該如何幫助你? –