试图扩展<asp:boundfield> </asp:boundfield>

时间:2014-12-03 16:57:39

标签: html asp.net vb.net custom-controls custom-data-attribute

我正在尝试扩展ASP:BoundField并覆盖InitializeDataCell事件以执行自定义数据绑定。我创建了一个继承自System.Web.UI.WebControls.BoundField的类(我将在下面发布一些代码)。我在HTML中注册标记时遇到问题,我不知道注册标记是错误还是类代码错误。类代码:

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace cc_custom
    Public Class cc_custom
        Inherits System.Web.UI.WebControls.BoundField


    <DefaultValue("")> _
    Public Property TestData As String
        Get
            Dim val As Object = MyBase.ViewState("TestData ")
            If val IsNot Nothing Then
                Return DirectCast(val, String)
            End If
            Return String.Empty
        End Get
        Set(value As String)
            If Not Object.Equals(value, MyBase.ViewState("TestData ")) Then
                MyBase.ViewState("TestData ") = value
                Me.OnFieldChanged()
            End If
        End Set
    End Property


        Protected Overrides Sub InitializeDataCell(cell As DataControlFieldCell, rowState As DataControlRowState)
            If Not String.IsNullOrEmpty(Me.TestData) Then
                Dim oLabel As New Label
                AddHandler oLabel.DataBinding, New EventHandler(AddressOf Me.OnLabelDataBind)
                cell.Controls.Add(oLabel)
            End If
        End Sub

        Protected Sub OnLabelDataBind(sender As Object, e As EventArgs)
            Dim control As Control = DirectCast(sender, Control)
            Dim namingContainer As Control = control.NamingContainer
            Dim dataValue As Object = Me.GetValue(namingContainer)

            If TypeOf control Is Label Then
                TryCast(control, Label).Text =  'Call to library_function(Me.TestData) will go here
            Else
                MyBase.OnDataBindField(sender, e)
            End If

        End Sub

    End Class
End Namespac

HTML中的注册标记

<%@ Register Namespace="cc_custom" Assembly="cc_custom " TagPrefix="tzc"  %>

最后是Gridview:

<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="False">
    <Columns>
        <tzc:cc_custom TestData="OrderDate" />                
    </Columns>
</asp:GridView>

我得到的错误是&#34;无法加载文件或程序集&#39; cc_custom&#39;或其中一个依赖项。系统找不到指定的文件。&#34;我试图在代码和HTML中改变一切,但似乎没有任何效果。我发现的所有例子都使用了相同的图片。

0 个答案:

没有答案