怎样在asp.net页面中实现如图所示的文件目录式的选择。 就是在左边选择一项,右边自动把那一项显示出来
这个左右是一个框架。左侧可以用asp:TreeView控件实现。
具体的代码你可以参考:
''' <summary>
''' 初始加载树控件
''' </summary>
''' <param name="userId"></param>
Private Sub Innit(ByVal userId As String)
Dim BLL_User As New HLPM.BLL.SYS.SYS_User
Dim FolderSet As DataSet = BLL_User.Get_Menu_List("User_id='" + userId + "'", "sort")
Me.TreeView_Menu.Nodes.Clear()
If FolderSet.Tables(0).Rows.Count > 0 Then
For i As Integer = 0 To FolderSet.Tables(0).Rows.Count - 1
'加载父节点
Dim fatherNode As New TreeNode()
If FolderSet.Tables(0).Rows(i)("Parent_Id").ToString() = "0" Then
fatherNode.Value = FolderSet.Tables(0).Rows(i)("ID").ToString()
fatherNode.Text = FolderSet.Tables(0).Rows(i)("menu").ToString()
fatherNode.NavigateUrl = "#"
fatherNode.ToolTip = FolderSet.Tables(0).Rows(i)("description").ToString()
fatherNode.ImageToolTip = FolderSet.Tables(0).Rows(i)("description").ToString()
fatherNode.ImageUrl = "~/images/tree/folder_closed.gif"
fatherNode = GetTreeNode(fatherNode, FolderSet)
Me.TreeView_Menu.Nodes.Add(fatherNode)
End If
Next
End If
End Sub
''' <summary>
''' 子节点
''' </summary>
''' <param name="fatherNode"></param>
''' <param name="dataset"></param>
''' <returns></returns>
Public Shared Function GetTreeNode(ByVal fatherNode As TreeNode, ByVal dataset As DataSet) As TreeNode
For i As Integer = 0 To dataset.Tables(0).Rows.Count - 1
Dim childNode As New TreeNode()
If dataset.Tables(0).Rows(i)("Parent_Id").ToString() = fatherNode.Value Then
childNode.Value = dataset.Tables(0).Rows(i)("ID").ToString()
childNode.Text = dataset.Tables(0).Rows(i)("menu").ToString()
childNode.NavigateUrl = dataset.Tables(0).Rows(i)("address").ToString()
childNode.ToolTip = dataset.Tables(0).Rows(i)("description").ToString()
childNode.ImageToolTip = dataset.Tables(0).Rows(i)("description").ToString()
childNode.ImageUrl = "~/images/tree/tree_node.gif"
childNode.Target = dataset.Tables(0).Rows(i)("target").ToString()
childNode = GetTreeNode(childNode, dataset)
fatherNode.ChildNodes.Add(childNode)
End If
Next
Return fatherNode
End Function
效果如图。
您可以研究一下。如果有什么不清楚您可以追问。希望对您有用!