ASP.Net LINQ数据源错误是ListView
我有一个成功的查询,从 RESTAURANT 数据库的 REST_NAME 列返回 8 个项目。我的数据绑定成功,但当我尝试访问 LivtView 中的项目时,我收到错误:“System.String”不包含名为“REST_NAME”的属性。
数据访问层的LINQ查询:
public IEnumerable<string> getRestaurants(int cuisineID)
{
var restaurantList = from RESTAURANT in db.RESTAURANTs
where RESTAURANT.CUISINE_ID == cuisineID
orderby RESTAURANT.REST_NAME ascending
select RESTAURANT.REST_NAME;
return restaurantList;
}
业务逻辑层的函数:
public class BLgetRestaurants
{
public IEnumerable<string> getRestaurants(int cuisineID)
{
DLgetRestaurants obj = new DLgetRestaurants();
var restaurantList = obj.getRestaurants(cuisineID);
return restaurantList;
}
}
业务层函数的前端调用:
BLgetRestaurants obj = new BLgetRestaurants();
var restaurantListing = obj.getRestaurants(cuisineID);
ListRestaurants.DataSource = restaurantListing;
ListRestaurants.DataBind();
*最后,ListView调用得到REST_NAME 数据:**
<ItemTemplate>
<div id="RestName"><%#Eval("REST_NAME") %></div><br />
<div id="ListItems">
<div id="RestCuisine">Cuisine: </div>
<div id="RestCity">Location: </div>
<div id="RestAvgRating">Average Rating: </div>
<div id="RestPrice">Price: </div>
</div>
</ItemTemplate>
感谢您的帮助! 〜苏珊〜
I have a successful query that is returning 8 items from REST_NAME columen of the RESTAURANT db. I have a successful databind but when I try to access the item in the LivtView I receive an error: 'System.String' does not contain a property with the name 'REST_NAME'.
LINQ query from Data Access Layer:
public IEnumerable<string> getRestaurants(int cuisineID)
{
var restaurantList = from RESTAURANT in db.RESTAURANTs
where RESTAURANT.CUISINE_ID == cuisineID
orderby RESTAURANT.REST_NAME ascending
select RESTAURANT.REST_NAME;
return restaurantList;
}
Function in Business Logic Layer:
public class BLgetRestaurants
{
public IEnumerable<string> getRestaurants(int cuisineID)
{
DLgetRestaurants obj = new DLgetRestaurants();
var restaurantList = obj.getRestaurants(cuisineID);
return restaurantList;
}
}
Front End call of Business Layer function:
BLgetRestaurants obj = new BLgetRestaurants();
var restaurantListing = obj.getRestaurants(cuisineID);
ListRestaurants.DataSource = restaurantListing;
ListRestaurants.DataBind();
*Finally, the ListView call to get the REST_NAME data:**
<ItemTemplate>
<div id="RestName"><%#Eval("REST_NAME") %></div><br />
<div id="ListItems">
<div id="RestCuisine">Cuisine: </div>
<div id="RestCity">Location: </div>
<div id="RestAvgRating">Average Rating: </div>
<div id="RestPrice">Price: </div>
</div>
</ItemTemplate>
Thanks for your help!
~susan~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
如果您正在处理具有
REST_NAME
的IEnumerable
,则可以使用<%#Eval("REST_NAME") %>
作为它的领域之一。但由于您使用的是IEnumerable
您不能这样做。Try
You can use
<%#Eval("REST_NAME") %>
if you are dealing withIEnumerable<Restaurant>
which hasREST_NAME
as one of it's fields. But since you are usingIEnumerable<string>
you cannot do that.