自定义*任意* TemplateField 定义
我正在动态构建 GridView,并且我想预先定义要按需包含的 TemplateFields。因此,我想做的是拥有一个声明性文件,用于定义不同模板如何查找特定列。例如:
<asp:TemplateField>
<HeaderTemplate>
this is a text column
</HeaderTemplate>
<ItemTemplate>
data goes here
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Text="databindhere" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
this is a bool column
</HeaderTemplate>
<ItemTemplate>
if(true) "yes" else "no"
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox Checked="databindme" />
</EditItemTemplate>
</asp:TemplateField>
因此,如果我的查询有一个文本和两个布尔字段,我可以根据需要将适当的 TemplateFields 推送到 Columns 属性中。 (我希望我在这里说得通)
那么,我将如何为上述定义创建声明性文件?然后,我如何以编程方式引用这些定义?
好的,最有效的方法是子类化 System.Web.UI.WebControls.TemplateField,但是当我这样做时,我似乎无法使用 <%@ Register %> 来使用该对象。指示。如果可以的话,我会使用新的衍生工具创建一些 UserControl,然后根据需要将它们 LoadControl() 和 Add() 到网格的列中。
有什么想法吗?
I'm building a GridView on the fly, and I'd like to pre-define the TemplateFields to be included ondemand. So, what I'd like to do is have a declarative file that defines how the different templates look for a specific column. Like:
<asp:TemplateField>
<HeaderTemplate>
this is a text column
</HeaderTemplate>
<ItemTemplate>
data goes here
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Text="databindhere" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
this is a bool column
</HeaderTemplate>
<ItemTemplate>
if(true) "yes" else "no"
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox Checked="databindme" />
</EditItemTemplate>
</asp:TemplateField>
So, if my query had a text and two bool fields, I could push the appropriate TemplateFields in the the Columns property as needed. (I hope I'm making sense here)
So, how would I go about creating declarative files for the above definitions? And then, how would I reference those definitions programmatically?
Ok, what would work best is to subclass System.Web.UI.WebControls.TemplateField, but when I do that, I can't seem to use the object with the <%@ Register %> directive. If I could, I'd create a handful of UserControls with the new derivative, and then LoadControl() and Add() them to the Columns of my grid as needed.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论