[英]How to bind a telerik grid column to a child data object that is a list?
I have a grid that binds a number of child data objects to columns with no issue, using the syntax defined at http://www.telerik.com/help/aspnet-ajax/grdbindingtosubobjects.html . 我有一个网格,使用http://www.telerik.com/help/aspnet-ajax/grdbindingtotosubobjects.html定义的语法,可以毫无问题地将许多子数据对象绑定到列。
What I can't figure out, however, is how to aggregate a child object that is a list or collection. 但是,我不知道的是如何聚合作为列表或集合的子对象。 For example, if I have a Customer object and I want to get the customer's first street address, I would use
DataField="Customer.Addresses[0].Street"
on a standard GridBoundColumn
. 例如,如果我有一个Customer对象,并且想获得该客户的第一个街道地址,则可以在标准
GridBoundColumn
上使用DataField="Customer.Addresses[0].Street"
。 How can I get the count of the addresses? 如何获得地址数? I have tried all sorts of GridCalculatedColumn DataFields and Expressions, to no avail.
我尝试了各种GridCalculatedColumn DataFields和Expressions,但都没有用。 I am looking for something along the lines of this:
我正在寻找与此类似的东西:
That doesn't work, of course. 当然,那是行不通的。 In fact, if I try to do a Count on any dotted data field, I get an exception of
实际上,如果我尝试对任何点分数据字段进行计数,都会得到一个例外
" System.Data.SyntaxErrorException: Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier. "
“ System.Data.SyntaxErrorException:聚合参数中的语法错误:期望带有可能的'Child'限定符的单列参数。
For example, just trying to use an expression of Count({0})
with DataFields set to Customer.FirstName
(of which there is only one), causes that exception to be thrown at runtime. 例如,仅尝试使用DataFields设置为
Customer.FirstName
(其中只有一个)的Count({0})
表达式,将导致在运行时引发该异常。 Doing the same thing with a non-dotted data field, such as SendDate, does not cause the same exception. 对不带点的数据字段(例如SendDate)执行相同的操作不会导致相同的异常。
Seems like you already received an answer to this question from the Telerik forums but for people that might stumble upon this question looking for an answer. 似乎您已经从Telerik论坛上收到了该问题的答案,但对于可能偶然发现该问题的人来说,这是一个好答案。
Essentially the RadGrid does not support having Collections in its DataFields, and the supported bindable property types can be found here . 本质上,RadGrid不支持在其DataField中包含Collections,并且可以在此处找到受支持的可绑定属性类型。 So in terms of this aggregation you could either do a calculation across this collection before binding it to the RadGrid and have an aggregate column defined, or you could look into using footers much like in this demo .
因此,就这种聚合而言,您可以在将该集合绑定到RadGrid并定义一个聚合列之前对该集合进行计算,或者可以像本演示中一样使用页脚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.