如何获取 DynamicControl 的值?

发布于 2024-07-23 05:15:23 字数 346 浏览 2 评论 0原文

我正在使用 ASP.NET 动态数据功能来做一些有点奇怪的事情。 即,创建一个动态字段列表作为主对象的子对象。

所以基本上我有 Ticket.Fields。 主页列出了 Ticket 的所有字段,Fields 属性有一个 DynamicControl,可以生成控件列表以收集更多数据。

棘手的部分是,此列表还使用动态数据来生成控件,因此每个字段都可以是任何定义的 FieldTemplates...这意味着当我尝试获取值时,我不一定知道实际的数据控件是什么。

那么,如何获取 DynamicControl 的值呢?

我是否需要创建 FieldTemplate 的新子类来提供获取该值的方法?

I'm using ASP.NET Dynamic Data functionality to do something a little weird. Namely, create a dynamic list of fields as children of the main object.

So basically I have Ticket.Fields. The main page lists all the fields for Ticket, and the Fields property has a DynamicControl that generates a list of controls to collect more data.

The tricky part is that this list ALSO uses Dynamic Data to generate the controls, so each field can be any of the defined FieldTemplates... meaning I don't necessarily know what the actual data control will be when I try to get the value.

So, how do I get the value of a DynamicControl?

Do I need to create a new subclass of FieldTemplate that provides a means to get at the value?

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

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

发布评论

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

评论(1

℡Ms空城旧梦 2024-07-30 05:15:23

睡个好觉会有惊人的效果。

好吧,扩展 FieldTemplate 只是为了意识到它已经为您公开了数据控件...

foreach (ListViewDataItem i in lvFields.Items)
    {         
        var val = i.FindDynamicControlRecursive("ValueText") as DynamicControl;
        var ft = val.FindFieldTemplate("ValueText") as FieldTemplateUserControl;

        ParseControl(ft.DataControl)
    } 

ParseControl 是在这里组成的,但我实际上有一个类可以为我处理该部分...所以希望未来的读者至少会在这里得到这个想法。

重要的一点是将 FindFieldTemplate 的结果转换为 FieldTemplateUserControl。 由于某种原因,它只返回 Control,尽管看起来它应该只能返回 FieldTemplateUserControls。 我想您可以通过更改字段生成器类来覆盖字段模板......但仍然如此。

It's amazing what a good nights sleep will do.

Well, that and going to extend FieldTemplate only to realize it already exposes the data control for you...

foreach (ListViewDataItem i in lvFields.Items)
    {         
        var val = i.FindDynamicControlRecursive("ValueText") as DynamicControl;
        var ft = val.FindFieldTemplate("ValueText") as FieldTemplateUserControl;

        ParseControl(ft.DataControl)
    } 

ParseControl is made up here, but I actually have a class laying around that can handle that part for me... so hopefully future readers will at least get the idea here.

The important bit is to cast the result of FindFieldTemplate to FieldTemplateUserControl. For some reason it just returns Control, even though it seems like it should only be able to return FieldTemplateUserControls. I guess you could override what field templates are by changing the field generator class... but still.

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