使用动态数据时如何从下拉列表中过滤选项?

发布于 2024-08-09 10:10:17 字数 294 浏览 2 评论 0原文

我觉得这应该很容易,但我没有看到任何方法可以做到。

我正在将 ASP.NET 动态数据与 Linq to SQL 结合使用。我有一张与技术人员协会相关的桌子。父属性是 TechAssignment,在 Web 表单上我使用 DynamicField 来显示它。

这确实工作得很好,它正确地将其视为外键字段,并使用该模板为我提供一个下拉列表,其中包含技术人员表中的技术人员列表。

唯一的问题是,它为我提供了所有技术人员的列表,而有相当多的技术人员不活跃。如何让动态数据过滤掉不活跃的技术人员,使他们无法被选择?

I feel like this should be easy, but I don't see any way to do it.

I'm using ASP.NET Dynamic Data with Linq to SQL. I've got a table with an Association to the Technician table. The Parent Property is TechAssignment, and on the web form I'm using a DynamicField to display it.

This works fine really, it correctly sees it as a ForeignKeyField and uses that template to give me a dropdown with a list of techs from the Technicians table.

The only problem is that it gives me a list of ALL the technicians, when there are quite a few who are inactive. How can I tell Dynamic Data to filter out inactive technicians so they can't be selected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

星光不落少年眉 2024-08-16 10:10:17

LINQ to SQL 生成部分类。

  1. 添加新属性(从其他外键属性复制)
  2. 在 get 中应用过滤器(通过 LINQ2SQL 或过滤原始属性)
  3. 绑定到该属性

关联表中的示例 UnapprovedContacts

public partial class Association
{
    public IList<Contact> UnapprovedContacts
    {
        get
        {
            return Contacts.Where(c => !c.IsApproved).ToList();
        }
    }
}

LINQ to SQL generates partial classes.

  1. Add a new property (copy from the other foreign key property)
  2. Apply the filter in the get (either by LINQ2SQL or filtering the original property)
  3. Bind to that property

Example UnapprovedContacts in Association table

public partial class Association
{
    public IList<Contact> UnapprovedContacts
    {
        get
        {
            return Contacts.Where(c => !c.IsApproved).ToList();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文