温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:NetShopForge网上商店程序(VB)源码
当前文件:
NetShopForge/Library/Componets/Categories/CategoryTree.vb[2K,2009-6-12 11:49:45],打开代码结构图
NetShopForge/Library/Componets/Categories/CategoryTree.vb[2K,2009-6-12 11:49:45],打开代码结构图1Imports System.Data 2
Imports System.Web.UI.WebControls 3
Namespace NetShopForge.Library.Category 4
Public Class CategoryTree 5
6
Private Shared _Instance As CategoryTree 7
Public Shared ReadOnly Property Instance() As CategoryTree 8
Get 9
If IsNothing(_Instance) Then 10
_Instance = New CategoryTree 11
End If 12
Return _Instance 13
End Get 14
End Property 15
16
Private Sub BindData(ByRef listControl As System.Web.UI.WebControls.ListControl, ByVal dt As DataTable, ByVal categoryFatherID As String, ByVal categoryFatherName As String, ByVal IsOnlyTop As Boolean, ByVal PathSeparator As String) 17
Using dv As DataView = New DataView(dt) 18
dv.RowFilter = "CategoryFatherID = " & categoryFatherID.ToString() 19
20
For Each drv As DataRowView In dv 21
22
Dim categoryName As String = categoryFatherName 23
Dim categoryID As String = drv("CategoryID").ToString() 24
If categoryFatherID <> -1 Then 25
categoryName = String.Format("{0}{1}{2}", categoryName, PathSeparator, drv.Item("CategoryName")) 26
Else 27
categoryName = drv.Item("CategoryName") 28
End If 29
30
listControl.Items.Add(New ListItem(categoryName, CInt(categoryID))) 31
If Not IsOnlyTop Then 32
BindData(listControl, dt, categoryID, categoryName, False, PathSeparator) 33
End If 34
Next 35
End Using 36
37
End Sub 38
39
Public Sub SetCategoryList(ByRef listControl As System.Web.UI.WebControls.ListControl) 40
SetCategoryList(listControl, "") 41
End Sub 42
Public Sub SetCategoryList(ByRef listControl As System.Web.UI.WebControls.ListControl, ByVal firstText As String) 43
SetCategoryList(listControl, firstText, False) 44
End Sub 45
46
''' <summary> 47
''' 48
''' </summary> 49
''' <param name="listControl"> and listControl from System.Web.UI.WebControls.ListControl</param> 50
''' <param name="firstText">the list's first caption ,value=-1 </param> 51
''' <param name="IsOnlyTop"></param> 52
''' <remarks></remarks> 53
Public Sub SetCategoryList(ByRef listControl As System.Web.UI.WebControls.ListControl, ByVal firstText As String, ByVal IsOnlyTop As Boolean) 54
Using t As DataTable = CategoryController.GetTreeTable 55
56
BindData(listControl, t, -1, "", IsOnlyTop, " > ") 57
If firstText.Length > 0 Then 58
listControl.Items.Insert(0, New ListItem(firstText, -1)) 59
End If 60
End Using 61
End Sub 62
63
End Class 64
End Namespace 65
66







