开发者

Using User Controls in FormView templates

I find the repetition of sets of controls for each of the EditItem开发者_JAVA百科Template, 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜