在 FormView 模板中使用用户控件

发布于 2024-08-30 06:48:35 字数 206 浏览 10 评论 0原文

我发现 FormView 的每个 EditItemTemplate、InsertItemTemplate 和 ItemTemplate 模板的重复控件集在复制布局和代码等方面是乏味且危险的。我宁愿创建一个 xxxDetails 用户控件,并在每个模板,将布局和代码位置剪切到一个位置。

然而,这给数据绑定场景带来了一些复杂性。在这些场景中使用用户控件是否有任何既定的模式或实践指南?

I find the repetition of sets of controls for each of the EditItemTemplate, InsertItemTemplate, and ItemTemplate templates of a FormView to be tedious and risky, in terms duplicating layout and code etc. I would much rather create a xxxDetails user control, and use this in each template, cutting layout and code location down to one location.

However, this introduces several complexities for data binding scenarios. Are there any extablished patterns or practice guides for using user controls in these scenarios?

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

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

发布评论

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

评论(1

苍景流年 2024-09-06 06:48:35

Microsoft 刚刚在 ASP.NET 4.0 中添加了对此的真正强大支持。它被称为动态数据。他们在所有数据控件上添加了名为 EnableDynamicData(type) 的方法。 ASP.NET 中包含默认模板,但您可以创建自己的模板。

要使用内置的自定义模板,只需在文件夹中添加 DynamicData/Templates 目录即可。在其中,您可以添加类型视图,插入和编辑所有数据类型的模板。默认模板内置了验证器,因此它们是一个很好的起点!

以下是我为在 DynamicData 模板中使用自定义控件整理的示例。我使用滑块来编辑整数,使用CurrencyInput 来编辑货币等...

如果您可以使用 ASP.NET 4.0,我强烈建议您这样做。此外,即使您不能,您仍然可能希望使用预构建的模板作为指导。

Microsoft just added really great support for this in ASP.NET 4.0. It is called DynamicData. They added methods on all data controls called EnableDynamicData(type). There are default templates included in ASP.NET, but you can make your own.

To use built custom templates, just add a DynamicData/Templates directory in your folder. Inside it you can add type views insert and edit templates for all of your data types. The default templates have validators built in so they are a great starting point!

Here is a sample I put together for using custom controls in DynamicData templates. I used a slider for editing integers, and CurrencyInput for money etc...

If you can go with using ASP.NET 4.0 I would highly recommend doing this. Also, even if you can't, you still might want to use the pre-built templates as guidance.

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