Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将计算列绑定到GridView_Asp.net_Sql Server 2008_Asp.net 4.0 - Fatal编程技术网

Asp.net 将计算列绑定到GridView

Asp.net 将计算列绑定到GridView,asp.net,sql-server-2008,asp.net-4.0,Asp.net,Sql Server 2008,Asp.net 4.0,我正在使用ASP.NET4.0。我也检查了这个论坛上的几个链接,但没有找到符合我要求的解决方案 我有一个GridView,它使用方法中的查询填充。查询如下: SELECT district_name, count(record_id) FROM districts; 我禁用了自动创建列选项,并手动添加了两列,即:District和Count。很明显,第二列(即Count)不在数据源中,因为它是一个计算结果 有人建议我使用Evalcount,因此我尝试: <asp:BoundField D

我正在使用ASP.NET4.0。我也检查了这个论坛上的几个链接,但没有找到符合我要求的解决方案

我有一个GridView,它使用方法中的查询填充。查询如下:

SELECT district_name, count(record_id) FROM districts;
我禁用了自动创建列选项,并手动添加了两列,即:District和Count。很明显,第二列(即Count)不在数据源中,因为它是一个计算结果

有人建议我使用Evalcount,因此我尝试:

<asp:BoundField DataField=<%#Eval("count") %> /> 
但它也不起作用。我尝试创建TemplateField,但并没有失败

如何在GridView中包含此计数列?

替换

SELECT district_name, count(record_id) FROM districts;

<asp:BoundField DataField=<% #Eval("count") %> />


我在BoundField属性之间有逗号,比如一个白痴…

给计算列countrecord\u id提供别名,比如选择district\u name,countrecord\u id作为districts中的Count1;并像Evalcount1Error:Literal content那样使用它。我是这样使用的:但它给出了error:Literal content。前一个也可以使用。我正在使用ORM,POCO发生冲突。在POCO中添加了一个名为Count的自定义列,修复了该问题。
SELECT district_name, count(record_id) as count FROM districts;

<asp:BoundField DataField="count" />