我有這樣綁定LINQ查詢結果直放站
var businessList = (from u in _DB.Users
join cat in _DB.BusinessCategories on u.UserId equals cat.UserId
select new BusinessDetails(u.Businesses.FirstOrDefault(), u)).Skip(0).Take(10);
dlBusiness.DataSource = businessList.ToList();
dlBusiness.DataBind();
查詢我BUSINESSNAME作爲商務類的成員。我有一個DataList如下
<asp:DataList ID="dlBusiness" DataKeyField="UserId" runat="server" >
<ItemTemplate>
<%#Eval("Business.BusinessName")%>
</ItemTemplate>
</asp:DataList>
這裏是一流的界定及
public class BusinessDetails
{
public BusinessDetails(Business business,User user){
this._Business = business;
this._UserDetails = user;
}
private string _distance;
public string Distance
{
get { return _distance; }
set { _distance = value; }
}
private Business _Business;
public Business BusinessData
{
get { return _Business; }
set { _Business = value; }
}
private User _UserDetails;
public User UserDetails
{
get { return _UserDetails; }
set { _UserDetails = value; }
}
}
但這顯示空白?我如何將它綁定到DataList?
您可以添加BusinessDetails類的定義嗎?它是否有商業物業? – kmcc049
@ kmcc049新增。 –
刪除'DataKeyField =「UserId」'然後嘗試 – Ankur