自定义控件,继承自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不是很熟悉,可能有很多错误的地方,请指点一下
...全文
53 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
安全的FTP传输 Imports Org.Mentalis.Security.Ssl Imports Org.Mentalis.Security.Certificates Imports Org.Mentalis.Security.Cryptography Imports System Imports System.IO Imports System.Exception 'Imports Tamir.SharpSsh.java 'Imports Tamir.SharpSsh Imports SharpSSH_EXD Public Class SFTPHelper Private Sub New() End Sub Private m_sshCp As SshTransferProtocolBase Public ReadOnly Property Connected() As Boolean Get Return m_sshCp.Connected End Get End Property Public Sub New(ByVal connectionInfo As SshConnectionInfo) m_sshCp = New Sftp(connectionInfo.Host, connectionInfo.User) If (Not connectionInfo.Pass Is Nothing) Then m_sshCp.Password = connectionInfo.Pass End If If Not connectionInfo.IdentityFile Is Nothing Then m_sshCp.AddIdentityFile(connectionInfo.IdentityFile) End If End Sub Public Sub Connect() If (m_sshCp.Connected = False) Then Try m_sshCp.Connect(10022) ' m_sshCp.Connect() ' Dim i As Integer = m_sshCp.Port Catch ex As System.Exception ' Dim str As String = ex.ToString ' Dim a As Integer = 0 m_sshCp.Close() End Try End If End Sub Public Sub Close() If (m_sshCp.Connected) Then m_sshCp.Close() End If End Sub Public Function Upload(ByVal localPath As String, ByVal remotePath As String) As String Try If (m_sshCp.Connected = False) Then m_sshCp.Connect(10022) End If Try m_sshCp.Put_resume(localPath, remotePath) 'm_sshCp.RemoveFile(remotePath) ' Return "Remote File has already exists. delete file" Catch ex As Tamir.SharpSsh.jsch.SftpException m_sshCp.RemoveFile(remotePath) Return "Remote File has already exists. delete file" End Try Return "" Catch ex As Exception Return ex.Message End Try End Function Public Function Download(ByVal remotePath As String, ByVal localPath As String) As Boolean Try If (m_sshCp.Connected = False) Then m_sshCp.Connect(10022) End If m_sshCp.Get(remotePath, localPath) Return True Catch Return False End Try End Function Public Function CheckFileLength(ByVal filePath As String) As Long Try 'Dim stream As New Tamir.SharpSsh.SshStream(filePath.Replace(".TMP", ".TXT"), m_sshCp.Username, m_sshCp.Password) 'Return stream.Length If (m_sshCp.Connected = False) Then m_sshCp.Connect(10022) End If Return m_sshCp.GetFileLength(filePath) Catch ex As Exception Dim str As String = ex.ToString End Try Return 0 End Function Public Sub SetFileLength(ByVal filePath As String) 'set 0 Try 'Dim stream As New Tamir.SharpSsh.SshStream(filePath.Replace(".TMP", ".TXT"), m_sshCp.Username, m_sshCp.Password) 'Return stream.Length If (m_sshCp.Connected = False) Then m_sshCp.Connect(10022) End If m_sshCp.SetFileLength(filePath) Catch ex As Exception Dim str As String = ex.ToString End Try End Sub Public Function RenameFile(ByVal oldPath As String, ByVal newPath As String) As Boolean Dim blnResult As Boolean = False Try If (m_sshCp.Connected = False) Then m_sshCp.Connect(10022) End If m_sshCp.RenameFile(oldPath, newPath) blnResult = True Catch ex As Exception blnResult = False End Try Return blnResult End Function End Class Public Class SshConnectionInfo Private _user As String Private _pass As String Private _host As String Private _identityFile As String Public Property User() As String Get Return _user End Get Set(ByVal value As String) _user = value End Set End Property Public Property Pass() As String Get Return _pass End Get Set(ByVal value As String) _pass = value End Set End Property Public Property Host() As String Get Return _host End Get Set(ByVal value As String) _host = value End Set End Property Public Property IdentityFile() As String Get Return _identityFile End Get Set(ByVal value As String) _identityFile = value End Set End Property End Class
发帖
.NET社区

6.0w+

社区成员

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

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

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