【问题标题】:Custom GridView with TemplateField and UserControl带有 TemplateField 和 UserControl 的自定义 GridView
【发布时间】:2014-05-07 10:53:40
【问题描述】:

我有一个自定义的 gridview 实现,它扩展了 ASP.Net Gridview 以在我的应用程序中执行一些特定的附加逻辑。

我已将必要的控制寄存器添加到 web.config 文件中,并将控件添加到这样的 UserControl 中。

<%@ Register TagPrefix="uc1" Namespace="MyApp.CustomControls" %>
<uc1:CustomGridView ID="userlist" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="ckbIsDefault" runat="server"/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="UserName" SortExpression="UserName" />
        <asp:BoundField DataField="FullName" SortExpression="FullName" />
    </Columns>
</uc1:CustomGridView>

当我查看由 Visual Studio 为用户控件自动生成的 .designer.cs 文件时,其中包含 CheckBox 元素的声明。当我使用 ASP.Net 的 gridview 而不是我的自定义 gridview 时,不会发生这种情况。

应用程序编译并运行良好。但我只是对不必要的字段声明感到恼火。即使我手动删除了该字段,只要我在 ASCX 文件中进行任何更改,它就会继续出现。

我的自定义 gridview 实现中是否缺少属性或其他内容?

【问题讨论】:

    标签: c# asp.net gridview user-controls custom-controls


    【解决方案1】:

    很遗憾没有人能给我解决这个问题的方法。但是经过2天的嘲笑,发现了问题。正是这个属性,我添加到了 CustomGridView 类中。

    ParseChildren(true,DefaultProperty = "Columns")
    

    但不知道,为什么删除它可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      相关资源
      最近更新 更多