获取数据库项的最大值

时间:2023-01-26 14:24:16

I'm working at the aspx page, and the following code is inserted in a Repeater control:

我在aspx页面工作,下面的代码被插入到中继器控件中:

<%# ((System.Collections.Generic.List<double>)DataBinder.Eval(Container.DataItem, "BookPrices")).Max() %>

Brings up the following error: 'System.Collections.Generic.List<double>' does not contain a definition for 'Max'

出现以下错误:“system . collection . generic . generic”。列表 '不包含“Max”的定义

List does have an method of Max(), so I'm possibly messing up my code somehow. What is my problem? BookPrices is a list<double> object, which I'd like to print it's maximum value.

List确实有Max()的方法,所以我可能把代码搞砸了。我的问题是什么?BookPrices是一个 对象的列表,我想将它的最大值打印出来。

P.S. You guys are great! I didn't find answers for many of my questions on the web. You really are life savers. Thank you very much! :)

附注:你们太棒了!我在网上找不到很多问题的答案。你真的是救生员。非常感谢!:)

1 个解决方案

#1


2  

Did you make sure to import System.Linq?

你确定要导入System.Linq吗?

List<T> does not actually have a Max method. Instead Max most often binds to the extension method Enumerable.Max. Linq needs to be imported in order for this to work.

List 实际上没有Max方法。相反,Max通常绑定到扩展方法Enumerable.Max。为了使其工作,需要导入Linq。

#1


2  

Did you make sure to import System.Linq?

你确定要导入System.Linq吗?

List<T> does not actually have a Max method. Instead Max most often binds to the extension method Enumerable.Max. Linq needs to be imported in order for this to work.

List 实际上没有Max方法。相反,Max通常绑定到扩展方法Enumerable.Max。为了使其工作,需要导入Linq。