简体   繁体   English

如何将Telerik网格列绑定到列表的子数据对象?

[英]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.

相关问题 在Telerik Grid中通过Ajax绑定数据时如何进行分组和聚合 - How to do grouping and aggregations when data bind by ajax in Telerik Grid 提交带有结果数据的表单后如何将返回的数据绑定到 Telerik ASP.Net Core 网格 - How to bind returned data to a Telerik ASP.Net Core grid after submitting a form with resulted data 将列表绑定到包含复选框列的数据网格视图 - Bind a List to Data Grid View which contains Check Box Column 如何将列表/字符串集合绑定到WPF中数据网格中列的行? - How can I bind a list/collection of strings to the rows of a column in a data grid in WPF? 如何将网格与对象绑定 - how to bind a grid with an object 将object []绑定到Telerik中的数据源 - Bind object[] to a datasource in Telerik 如何将数据绑定到Telerik muticolumn组合框? - How to bind data to telerik muticolumn combo box? 如何将SharePoint列表附件动态绑定到Kendo Grid列 - How to bind a SharePoint list attachment to a Kendo Grid column dynamically 如何使用Linq在Telerik Mvc网格中绑定前20条记录? - How to bind top 20 records in Telerik Mvc Grid using Linq? 如何使用Telerik将网格数据源与文本框绑定 - How to bind grid's datasource with textbox using Telerik
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM