在 GridView 中从不同的 ActiveRecord 表对象设置多个 DataKeyName

发布于 2024-07-28 22:29:49 字数 801 浏览 6 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抠脚大汉 2024-08-04 22:29:49

按照此处概述的模式,我能够解决该问题。

一个简短的解释...我创建了 CONFIGURATION 类的一个新的部分类(我这样做是因为我的 ActiveRecord 代码是自动生成的,并且我无法更改它。我确信无论如何这是强烈建议的用法,因为您的模型几乎总是具有部分类非常适合的扩展功能。

部分类如下:

Partial Public Class CONFIGURATION

    Public ReadOnly Property GetDealerID() As Integer
        Get
            Return LUserConfigurations.Item(0).Users.Dealer.ID
        End Get
    End Property
End Class

然后,我将 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:

Partial Public Class CONFIGURATION

    Public ReadOnly Property GetDealerID() As Integer
        Get
            Return LUserConfigurations.Item(0).Users.Dealer.ID
        End Get
    End Property
End Class

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文