自定义控件,继承自treeview,编写好后,在aspx文件中使用出错

zwq78 2008-05-08 12:43:34
代码如下:
Imports System.ComponentModel

Public Class tvCodeItem
Inherits WebControls.TreeView

#Region "Data Binding"

Private mValueMember As String
Private mDisplayMember() As String
Private mHasChild As Boolean
Private mPidMember As String
Private mCPtrMember As String
Private mDataTable As DataTable
Private mtv As TreeView

<Category("Data")> Public Property PidMember() As String
Get
Return mPidMember
End Get
Set(ByVal Value As String)
mPidMember = Value
End Set
End Property

<Category("Data")> Public Property CPtrMember() As String
Get
Return mCPtrMember
End Get
Set(ByVal Value As String)
mCPtrMember = Value
End Set
End Property
<Category("Data")> Public Property ValueMember() As String
Get
Return mValueMember
End Get
Set(ByVal Value As String)
mValueMember = Value
End Set
End Property

<Category("Data")> Public Property DisplayMember() As String
Get
Return Join(mDisplayMember, SPLITSTRING)
End Get
Set(ByVal Value As String)
mDisplayMember = Split(Value, SPLITSTRING)
End Set
End Property

<Category("Data")> Public Property DataSource() As DataTable
Get
Return mDataTable
End Get
Set(ByVal Value As DataTable)
mDataTable = Value
End Set
End Property
#End Region

Function GetValue(ByVal r As DataRow) As Object
Return r(mValueMember)
End Function

Function GetDisplay(ByVal r As DataRow) As Object
Dim i As Int32
Dim temp As String = ""
For i = 0 To mDisplayMember.Length - 1
temp = temp & IIf(i > 0, LINKSTRING, "") & r(mDisplayMember(i))
Next
Return temp
End Function

Function GetPid(ByVal r As DataRow) As Object
Return r(mPidMember)
End Function

Function GetCPtr(ByVal r As DataRow) As Boolean
Return r(mCPtrMember)
End Function

Public Sub Init(ByVal collid As Int32, Optional ByVal dispmember As String = "") ', _

If dispmember = "" Then
dispmember = DefaultShowFields
End If

If collid = 0 Then Exit Sub
If Me.CollectID = collid Then
Exit Sub
End If

Dim dt As DataTable, dtsource As DataTable
Dim filter As String = "collectid=" + collid.ToString
cbase.GetCodeItemDataRows(collid) '并不是进入系统就加载了所有CodeItem,所以需要在每次使用前调用GetCodeItemDataRows
dtsource = cbase.GetDataTable("codeitem")

dt = dtsource.Clone
Dim dr() As DataRow
dr = dtsource.Select(filter)
Dim i As Int32
For i = 0 To dr.Length - 1
dt.ImportRow(dr(i))
Next
With Me
.PidMember = "pid"
.CPtrMember = "cptr"
.DisplayMember = dispmember
.ValueMember = "id"
'要在所有字段成员赋值完成后,再给datasource写入值。
.DataSource = dt
End With

Me.FillTreeNode(Nothing, "pid=0")

Me.CollectID = collid

End Sub

Private Sub FillTreeNode(ByRef pnode As myTreeNode, ByVal filter As String)
If pnode Is Nothing Then mtv.Nodes.Clear()
Dim rows As DataRow() = Me.DataSource.Select(filter)
Dim r As DataRow
Dim newnode As myTreeNode
For Each r In rows
newnode = New myTreeNode(GetDisplay(r), GetValue(r), GetPid(r), GetCPtr(r))

newnode.PopulateOnDemand = newnode.CPtr
newnode.SelectAction = TreeNodeSelectAction.Expand

If pnode Is Nothing Then
mtv.Nodes.Add(newnode)
Else
pnode.ChildNodes.Add(newnode)
End If
'If newnode.CPtr Then
' Me.FillTreeNode(newnode, "pid=" + newnode.Value.ToString)
'End If
Next
End Sub

Private mCollectID As Int32

Public Property CollectID() As Int32
Get
Return mCollectID
End Get
Set(ByVal Value As Int32)
mCollectID = Value
End Set
End Property


Public Sub New(ByRef tv As TreeView)
Me.mtv = tv

End Sub

Public Sub tvBeforeExpand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)
If e.Node.PopulateOnDemand Then
FillTreeNode(CType(e.Node, myTreeNode), "pid=" + e.Node.Value.ToString)
End If
End Sub
End Class

使用时:

<%@ Register TagPrefix="nhw" TagName="uctv" Src="tvCodeItem.vb"%>


总是出错,对web不是很熟悉,可能有很多错误的地方,请指点一下
...全文
48 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
.NET社区
加入

6.0w+

社区成员

.NET技术交流专区
社区管理员
  • ASP.NET
  • R小R
  • 喵叔哟
帖子事件
创建了帖子
2008-05-08 12:43
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。