急问用户自定义控件的问题!!急急急!!!大家来帮忙
我用MS.NET的VB编写了一个自定义控件,继承来自DataList 控件
但是我一加入设计器就出错
第一个类
Imports System.ComponentModel
Imports System.Web.UI
Imports System
Imports System.Web
Imports System.Web.UI.WebControls
<Assembly: TagPrefix("CategoryShowControls1", "CategoryShowControls1")>
Namespace CategoryShowControls1
'Designer("CategoryShowControls1.CategoryShowDesigner")这句话加入到下面就出错
<Designer("CategoryShowControls1.CategoryShowDesigner"), ToolboxData("<{0}:CategoryShow runat=server></{0}:CategoryShow>")> Public Class CategoryShow
Inherits System.Web.UI.WebControls.DataList
Dim _text As String
<Browsable(True), Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
Dim category As New ShopGoByGo.WebModules.Product.Business.Category
Dim categoryDataView As DataView = category.Get_Highest_Categories.Tables(0).DefaultView
'Dim theDataList As New DataList
Me.DataKeyField = "ProductCategoryId"
Me.ItemTemplate = New MyTemplate(ListItemType.Item)
Me.DataSource = categoryDataView
Me.DataBind()
MyBase.Render(output)
End Sub
End Class
End Namespace
第二个类,关键就是这个
Imports System
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design
Imports System.ComponentModel.Design
Namespace CategoryShowControls1
Public Class CategoryShowDesigner
Inherits System.Web.UI.Design.ControlDesigner
Public Overrides Function GetDesignTimeHtml() As String
' Dim sw As New StringWriter
'Dim tw As New HtmlTextWriter(sw)
'Dim category As New ShopGoByGo.WebModules.Product.Business.Category
' Dim categoryDataView As DataView = category.Get_Highest_Categories.Tables(0).DefaultView
' Dim theDataList As New DataList
'theDataList.DataKeyField = "ProductCategoryId"
'theDataList.ItemTemplate = New MyTemplate(ListItemType.Item)
'theDataList.DataSource = categoryDataView
'theDataList.DataBind()
'theDataList.RenderControl(tw)
' Return sw.ToString()
End Function
End Class
End Namespace
第三个类
Imports System.ComponentModel
Imports System.Web.UI
Imports System
Imports System.Web
Imports System.Web.UI.WebControls
Namespace CategoryShowControls1
Public Class MyTemplate
Implements ITemplate
Shared itemcount As Integer = 0
Dim TemplateType As ListItemType
Sub New(ByVal type As ListItemType)
TemplateType = type
End Sub
Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim lc As New Literal
Select Case TemplateType
Case ListItemType.Item
AddHandler lc.DataBinding, AddressOf TemplateControl_DataBinding
End Select
container.Controls.Add(lc)
itemcount += 1
End Sub
Private Sub TemplateControl_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lc As Literal
lc = CType(sender, Literal)
Dim container As DataListItem
container = CType(lc.NamingContainer, DataListItem)
lc.Text &= "<TABLE cellSpacing='0' cellPadding='0' border='0'><TBODY><TR><TD style='COLOR: #000076' align='left'>·<A href='' >'"
lc.Text &= DataBinder.Eval(container.DataItem, "ProductCategoryName") & "</A>"
lc.Text &= "</TD></TR></TBODY></TABLE>"
End Sub
End Class
End Namespace