一、控件页面的设置
<%@ Register TagPrefix="componentart" NameSpace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<COMPONENTART:TREEVIEW id="TreeViewModules" runat="server" LineImagesFolderUrl="images/lines/" ShowLines="true"
LeafNodeImageUrl="images/folder.gif" ParentNodeImageUrl="images/folders.gif" NodeLabelPadding="3" DefaultImageHeight="16"
DefaultImageWidth="16" LineImageHeight="20" LineImageWidth="19" NodeEditCssClass="NodeEdit" HoverNodeCssClass="HoverTreeNode"
SelectedNodeCssClass="SelectedTreeNode" NodeCssClass="TreeNode" CssClass="TreeView" KeyboardEnabled="false"
NodeEditingEnabled="false" DragAndDropEnabled="false" EnableViewState="true" Width="220" Height="400"></COMPONENTART:TREEVIEW>
二 后台代码文件
1.PAGE_LOAD事件
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
'Put user code to initialize the page here
BuildTree()
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
2. '建立目录数
Protected Sub BuildTree()
'获取数据源
Dim objInfo As New C_InfoController
Dim dbRow As DataRow
dsC_InfoModules = objInfo.GetdsC_InfoModules()
Dim I As Integer
Dim J As Integer
'通过循环建立模块所属站点级别的目录
For I = 0 To dsC_InfoModules.Tables(0).Rows.Count - 1
If I = 0 Then
newNode = CreateNode(CStr(dsC_InfoModules.Tables(0).Rows(0).Item("PortalName")), CStr(dsC_InfoModules.Tables(0).Rows(0).Item("PortalID")), True)
'newNode.Text = CStr(dsC_InfoModules.Tables(0).Rows(0).Item("PortalName"))
TreeViewModules.Nodes.Add(newNode)
PopulateSubTree("TabID", "TabName", newNode)
Else
For J = 0 To I - J - 1
If CInt(dsC_InfoModules.Tables(0).Rows(J + 1).Item("PortalID")) <> CInt(dsC_InfoModules.Tables(0).Rows(J).Item("PortalID")) Then
newNode = New TreeViewNode
newNode.Text = CStr(dsC_InfoModules.Tables(0).Rows(0).Item("PortalName"))
TreeViewModules.Nodes.Add(newNode)
PopulateSubTree("TabID", "TabName", newNode)
End If
Next
End If
Next
End Sub
3.'获取模块所属站点下的页面级别的目录数
Private Sub PopulateSubTree(ByVal NodeID As String, ByVal NodeName As String, ByVal node As TreeViewNode)
4. '添加模块级别的选项节点
Dim childNode As TreeViewNode = CreateNode(CStr(dsC_InfoModules.Tables(0).Rows(0).Item("ModuleTitle")), CStr(dsC_InfoModules.Tables(0).Rows(0).Item("ModuleID")), True)
childNode.ShowCheckBox = True
newNode.Nodes.Add(childNode)
5.创建节点函数
Private Function CreateNode(ByVal text As String, ByVal nodeValue As String, ByVal expanded As Boolean) As TreeViewNode
Dim node As TreeViewNode = New TreeViewNode
node.Text = text
node.Value = nodeValue
node.Expanded = expanded
Return node
End Function
三 引用该控件的aspx文件设置
1.页面设置
<%@ Register TagPrefix="Portal" TagName="TreeModules" Src="~/DesktopModules/C_Info/TreeModules.ascx" %><%@ Register TagPrefix="Portal" TagName="TreeModules" Src="~/DesktopModules/C_Info/TreeModules.ascx" %>
<portal:treemodules id="TreeModulesMore" runat="server"></portal:treemodules>
2.后台关键
'获取页面子控件页面中的TreeView控件
Dim treeViewModules As TreeView = CType(TreeModulesMore.FindControl("TreeViewModules"), TreeView)
Dim node As TreeViewNode
'遍历TreeView 控件中被选中的节点,并进行相应的操作
For Each node In treeViewModules.CheckedNodes
Dim IDs As String = Request.QueryString("IDs")
If IDs <> "" Then
Dim objInfo As New C_InfoController
Select Case Request.QueryString("Type")
Case "copy"
Case "move"
IDs &= "-1"
objInfo.MoveC_Info(IDs, CInt(node.Value))
Response.Write("<script language=javascript>window.opener.location.reload();</script>")
End Select
Response.Write("<script language=javascript>window.opener=null;window.close();</script>")
End If
Next