急问用户自定义控件的问题!!急急急!!!大家来帮忙

xzcastle 2005-06-23 12:22:22
我用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

...全文
58 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhongwanli 2005-06-23
  • 打赏
  • 举报
回复
在类定以前加上

[Serializable()] ///属性标签
public Class MyDataList
{
/// ....
}

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧