[英]Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource
I have a query like the following: 我有一个类似以下的查询:
var count = db.Employees.Count (x =>(x.Salary >0));
Grid1.DataSource = count.ToString();
Grid1.DataBind();
It is working fine. 一切正常。 However, why is Grid
displaying the output column by column? 但是,为什么Grid
逐列显示输出?
Your query returns an int
. 您的查询返回一个int
。 You can't use an integer as datasource for a gridview. 您不能使用整数作为gridview的数据源。 The error-message is self-explanatory: the DataSource
must be a type that implements IListSource
, IEnumerable
or IDataSource
(a GridView
usually displays multiple items). 错误消息是不言自明的: DataSource
必须是实现IListSource
, IEnumerable
或IDataSource
( GridView
通常显示多个项目)。
Maybe you want to use Where
instead of Count
: 也许您想使用Where
而不是Count
:
var employeeWithSalary = db.Employees.Where(x => x.Salary > 0);
Grid1.DataSource = employeeWithSalary;
Grid1.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.