categorytreecontrol_ss.ascx.vb
来自「C#语言制作asp.net网上商店的」· VB 代码 · 共 71 行
VB
71 行
Imports System.Data
Imports NetShopForge.Library.Category
Partial Class Shop_Controls_CategoryTreeControl_ss
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
hfCategoryID.Value = Request("CatID")
If hfCategoryID.Value.Length = 0 Then
hfCategoryID.Value = -1
End If
Dim cID As Integer = CInt(hfCategoryID.Value)
PopulateNodes(TreeView1.Nodes, cID)
If cID = -1 Then
CategoryTitle.Text = "商品类别"
Else
End If
End If
End Sub
Public Function GetTreeTable() As DataTable
Using dt As DataTable = HttpContext.Current.Cache("Treeview")
If IsNothing(dt) Then
Using t As DataTable = CategoryController.GetCategoryList(-2).Tables(0)
HttpContext.Current.Cache.Insert("Treeview", t)
Return t
End Using
End If
Return dt
End Using
End Function
Public Sub PopulateNodes(ByVal nodes As TreeNodeCollection, ByVal categoryFatherID As Integer)
Dim dt As New DataTable()
dt = GetTreeTable()
Dim strExpression As String
strExpression = String.Format("CategoryFatherID={0}", categoryFatherID)
Dim foundRows() As DataRow
foundRows = dt.Select(strExpression)
Dim I As Integer
For I = 0 To foundRows.GetUpperBound(0)
Dim tn As New TreeNode()
tn.Text = foundRows(I).Item("CategoryName").ToString()
tn.Value = foundRows(I).Item("CategoryID").ToString()
tn.NavigateUrl = String.Format("~/Category.aspx?CatID={0}", tn.Value)
Dim dr() As DataRow
dr = dt.Select("[CategoryFatherID] = " & tn.Value)
If categoryFatherID = -1 AndAlso dr.GetUpperBound(0) > -1 Then
tn.PopulateOnDemand = True
End If
nodes.Add(tn)
Next
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
PopulateNodes(e.Node.ChildNodes, e.Node.Value)
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?