在 GridView 中从不同的 ActiveRecord 表对象设置多个 DataKeyName
我正在尝试使用 asp.net GridView 的 DataKeyNames 属性设置两个数据键。
我有一个简单查询如下:
Castle.ActiveRecord.Queries.SimpleQuery<ARMapping.CONFIGURATION> c = new Castle.ActiveRecord.Queries.SimpleQuery<ARMapping.CONFIGURATION>(@"
select c from CONFIGURATION c left join c.LUserConfiguration luc left join luc.User u left join u.Dealer d left join c.TRUCK t");
在数据绑定操作中,将按如下方式评估经销商:
<
% Eval("LUserConfiguration.User.Dealer.DealershipID") %>
当我尝试设置 DataKeyNames="ID,LUserConfiguration.User.Dealer.DealershipID" 时,出现错误: “ DataBinding: 'ARMapping.CONFIGURATION' 不包含名为 'LUserConfiguration.User.Dealer.DealershipID' 的属性。”
在进行 Eval'd 时它不会抱怨,但我无法将 Eval 放入 DataKeyNames 属性中。
有任何想法吗?
I'm trying to set two datakeys using the DataKeyNames property of an asp.net GridView.
I have a simplequery as follows:
Castle.ActiveRecord.Queries.SimpleQuery<ARMapping.CONFIGURATION> c = new Castle.ActiveRecord.Queries.SimpleQuery<ARMapping.CONFIGURATION>(@"
select c from CONFIGURATION c left join c.LUserConfiguration luc left join luc.User u left join u.Dealer d left join c.TRUCK t");
In the databind operation, the dealership would be evaluated as follows:
<
% Eval("LUserConfiguration.User.Dealer.DealershipID") %>
But when I try to set DataKeyNames="ID,LUserConfiguration.User.Dealer.DealershipID", I get error:
" DataBinding: 'ARMapping.CONFIGURATION' does not contain a property with the name 'LUserConfiguration.User.Dealer.DealershipID'. "
It doesn't complain when it's Eval'd, but I can't put Eval in the DataKeyNames property.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照此处概述的模式,我能够解决该问题。
一个简短的解释...我创建了 CONFIGURATION 类的一个新的部分类(我这样做是因为我的 ActiveRecord 代码是自动生成的,并且我无法更改它。我确信无论如何这是强烈建议的用法,因为您的模型几乎总是具有部分类非常适合的扩展功能。
部分类如下:
然后,我将 GridView 的 DataKeyNames 属性设置为“ID,GetDealerID”,但现在页面加载时没有错误。 。
您必须确保创建一个属性,而不是一个函数(根据上面的链接)
Following the pattern outlined here, I was able to solve the problem.
A brief explanation... I created a new partial class of the CONFIGURATION class (I did this because my ActiveRecord code is auto-generated, and I couldn't change it. I'm sure this is highly suggested usage anyway, as your models almost always have extended functionality that a partial class is perfect for.
The partial class follows:
Then, I set the DataKeyNames attribute of the GridView to "ID,GetDealerID". I haven't tested, but the page is loading without error now.
You have to make sure you create a property, not a function (according to the link above).