0

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

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

SELECT district_name, count(record_id) FROM districts;

我禁用了自动创建列选项并手动添加了两列,即:District 和 Count。很明显,第二列,即 Count 不在 DataSource 中,因为它是计算结果。

有人建议我使用 #Eval("count") ,所以我尝试了:

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

但它也不起作用。我尝试创建 TemplateField,但没有失败。

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

4

2 回答 2

0

代替

SELECT district_name, count(record_id) FROM districts;

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

SELECT district_name, count(record_id) as count FROM districts;

<asp:BoundField DataField="count" />
于 2012-04-17T11:30:48.203 回答
0

我在 BoundField 属性之间有逗号,就像一个白痴......

于 2018-09-04T20:22:39.900 回答