0
我重寫了一些TreeView控件的asp.net功能。在這我給一級css類的樹視圖上的節點級別1或級別2.而對於其餘節點我不需要任何CSS類是assigned.My樹狀視圖類我在哪裏分配「騙子」的CSS類節點是這樣的:asp.net Treeview節點不保留節點選擇上的Css類
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
<Serializable()>
Public Class Node
Inherits TreeNode
Public Property NodeID As Integer
Public Property NodeType As enumNodeTypes
Public Property NodeParentID As Integer
Public Property StatusColor As ColorStatus
Public Property NodeName As String
Get
Return Me.Text
End Get
Set(ByVal value As String)
'Me.Text = value
Me.Text = HttpUtility.HtmlEncode(value)
End Set
End Property
Public Property NodeValue As String
Get
Return Me.Value
End Get
Set(ByVal value As String)
Me.Value = value
End Set
End Property
Public Property NodeDataSource As List(Of Node)
Public Property NodeImageUrl As String
Get
Return Me.ImageUrl
End Get
Set(ByVal value As String)
Me.ImageUrl = value
End Set
End Property
Public Property NodeNavigateUrl As String
Get
Return Me.NavigateUrl
End Get
Set(ByVal value As String)
Me.NavigateUrl = value
End Set
End Property
Public Property NodeTarget As String
Get
Return Me.Target
End Get
Set(ByVal value As String)
Me.Target = value
End Set
End Property
Public Property NodeToolTip As String
Get
Return Me.ToolTip
End Get
Set(ByVal value As String)
Me.ToolTip = value
End Set
End Property
'Private _CssClass As String
'Public Property CssClass As String
' Get
' Return _CssClass
' End Get
' Set(ByVal value As String)
' _CssClass = value
' End Set
'End Property
Public Sub New(ByVal strText As String, ByVal strValue As String, ByVal intNodeType As enumNodeTypes)
MyBase.New(HttpUtility.HtmlEncode(strText), strValue)
Me.NodeValue = intNodeType & ";" & strValue
NodeName = strText
NodeDataSource = New List(Of Node)
End Sub
'------- Added for Highrise Engineering ------------
Public Sub New(ByVal strText As String, ByVal strValue As String, ByVal intNodeType As enumNodeTypes, ByVal strNodeImageURL As String, ByVal strTreeID As String)
MyBase.New(HttpUtility.HtmlEncode(strText), strValue)
Me.NodeValue = intNodeType & ";" & strValue & ";" & strTreeID
Me.NodeImageUrl = strNodeImageURL
NodeName = strText
NodeDataSource = New List(Of Node)
End Sub
Public Sub New(ByVal strText As String, ByVal strValue As String, ByVal intNodeType As enumNodeTypes, ByVal strNodeImageURL As String)
MyBase.New(HttpUtility.HtmlEncode(strText), strValue)
Me.NodeValue = intNodeType & ";" & strValue
Me.NodeImageUrl = strNodeImageURL
NodeName = strText
NodeDataSource = New List(Of Node)
End Sub
'----------------------------------------------------
Public Sub New(ByVal strText As String, ByVal strValue As String, ByVal objSalesStatus As ColorStatus, ByVal intNodeType As enumNodeTypes)
MyBase.New(HttpUtility.HtmlEncode(strText), strValue)
'NodeValue = strValue
Me.NodeValue = intNodeType & ";" & strValue
NodeName = strText
NodeDataSource = New List(Of Node)
'objSaleStatus = New ColorStatus(1, "TempBooked", Drawing.Color.Red)
' ElseIf eachUnit.UnitSaleStatus = 5 Then
' ElseIf eachUnit.UnitSaleStatus = 3 Then
'objSaleStatus = New ColorStatus(1, "AgrrNotDoneSaleNotLock", Drawing.Color.SkyBlue)
' ElseIf eachUnit.UnitSaleStatus = 8 Then
'objSaleStatus = New ColorStatus(1, "AgrrNotDoneSaleLock", Drawing.Color.SkyBlue) 'Skybluewithlock(image)
' ElseIf eachUnit.UnitSaleStatus = 7 Then
'objSaleStatus = New ColorStatus(1, "AgrrDoneSaleLock", Drawing.Color.DarkBlue) 'DarkBluewithlock(image)
' ElseIf eachUnit.UnitSaleStatus = 6 Then
'objSaleStatus = New ColorStatus(1, "AgrrDoneSaleNotLock", Drawing.Color.DarkBlue) 'DarkBlue(image)
' Else
'objSaleStatus = New ColorStatus(1, "TempBooked", Drawing.Color.Red)
Select Case objSalesStatus.StatusName
Case "TempBooked"
Me.NodeImageUrl = "~\Images\10_Unsold.png"
Case "Hold"
Me.NodeImageUrl = "~\Images\20_On-Hold.PNG"
Case "TempTillDateBooked"
Me.NodeImageUrl = "~\Images\30_Temp-Booked.png"
Case "Booking"
Me.NodeImageUrl = "~\Images\40_Booking.png"
Case "AgrrNotDoneSaleNotLock"
Me.NodeImageUrl = "~\Images\50_Sold.png"
Case "AgrrDoneSaleNotLock"
Me.NodeImageUrl = "~\Images\60_Agreement.png"
'Anjali: for 13.0.12
'-------------------
'---------------------
Case "AgrrNotDoneSaleLock"
'Anjali: for 13.0.12: changed image
'-----------------------------------
Me.NodeImageUrl = "~\Images\50_Sold.png"
'---------------------
Case "AgrrDoneSaleLock"
'Anjali: for 13.0.12: changed image
Me.NodeImageUrl = "~\Images\50_Sold.png"
'----------------------
'Anjali: for 13.0.12
'----------------------
Case "BookingPSNotAttached"
Me.NodeImageUrl = "~\Images\50_Sold.png"
Case "Freeze"
Me.NodeImageUrl = "~\Images\50_Sold.png"
'----------------------
'13.0.25
'-------
'-------
'Case "TempBooked"
' Me.NodeImageUrl = "~\Images\HOUSE.bmp"
' 'Anjali: for 13.0.12
' '-------------------
'Case "TempTillDateBooked"
' Me.NodeImageUrl = "~\Images\HouseTemporaryTillDateBooking.png"
' '---------------------
'Case "AgrrNotDoneSaleNotLock"
' Me.NodeImageUrl = "~\Images\SoldHouse.bmp"
'Case "AgrrNotDoneSaleLock"
' 'Anjali: for 13.0.12: changed image
' '-----------------------------------
' Me.NodeImageUrl = "~\Images\SoldHouseLock.png"
' '---------------------
'Case "AgrrDoneSaleLock"
' 'Anjali: for 13.0.12: changed image
' Me.NodeImageUrl = "~\Images\SoldHouseAggDoneLock.png"
' '----------------------
'Case "AgrrDoneSaleNotLock"
' Me.NodeImageUrl = "~\Images\SoldHouseAggDone.bmp"
' 'Anjali: for 13.0.12
' '----------------------
'Case "Booking"
' Me.NodeImageUrl = "~\Images\HouseBooking.png"
'Case "BookingPSNotAttached"
' Me.NodeImageUrl = "~\Images\HouseBookingLock.png"
'Case "Freeze"
' Me.NodeImageUrl = "~\Images\HouseFreeze.png"
' '----------------------
' '13.0.25
' '-------
'Case "Hold"
' Me.NodeImageUrl = "~\Images\House_OnHold.PNG"
' '-------
End Select
End Sub
Public Sub New(ByVal strText As String, ByVal strValue As String, ByVal strImageURL As String, ByVal strNavigateURL As String, ByVal strTarget As String, ByVal intNodeType As enumNodeTypes)
MyBase.New(HttpUtility.HtmlEncode(strText), strValue, strImageURL, strNavigateURL, strTarget)
'NodeValue = strValue
Me.NodeValue = intNodeType & ";" & strValue
Me.NodeName = strText
Me.NodeImageUrl = strImageURL
Me.NodeNavigateUrl = strNavigateURL
Me.NodeTarget = strTarget
'Me.NodeType = intNodeType
NodeDataSource = New List(Of Node)
End Sub
'Protected Overrides Sub LoadViewState(ByVal savedState As Object)
' If savedState IsNot Nothing Then
' Dim myState() As Object = CType(savedState, Object())
' If myState(0) IsNot Nothing Then
' MyBase.LoadViewState(myState(0))
' End If
' If myState(1) IsNot Nothing Then
' CssClass = myState(1).ToString
' End If
' End If
'End Sub
'Protected Overrides Function SaveViewState() As Object
' Dim baseState As Object = MyBase.SaveViewState()
' Dim allStates(3) As Object
' allStates(0) = baseState
' allStates(1) = CssClass
' Return allStates
'End Function
Protected Sub Load(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim sbCss As New Text.StringBuilder
If (
Me.Depth < 3 And Me.Depth > 0) Then
writer.AddAttribute("class", "con")
End If
End Sub
Protected Sub Init(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim sbCss As New Text.StringBuilder
If (
Me.Depth < 3 And Me.Depth > 0) Then
writer.AddAttribute("class", "con")
End If
End Sub
Protected Overrides Sub RenderPreText(ByVal writer As System.Web.UI.HtmlTextWriter)
'writer.AddAttribute("href", "")
''writer.AddAttribute("oncontextmenu", "alert('" & Me.NodeName & "');return false;")
'Project = 0
' Building = 1
' Wing = 2
' Unit = 3
'Parking = 5
If (Me.Depth < 3 And Me.Depth > 0) Then
writer.AddAttribute(HtmlTextWriterAttribute.Class, "con")
End If
'Me.NodeType <> 0 Dim sbMouseDownScript As New Text.StringBuilder
' sbMouseDownScript.Append("var rightclick;")
' sbMouseDownScript.Append("var e = window.event;")
' sbMouseDownScript.Append("if (e.which) rightclick = (e.which == 3);")
' sbMouseDownScript.Append("else if (e.button) rightclick = (e.button == 2);")
'sbMouseDownScript.Append("alert(rightclick);")
' sbMouseDownScript.Append("if (rightclick) alert('" & Me.NodeName & "');")
' writer.AddAttribute("onmousedown", sbMouseDownScript.ToString)
'writer.AddAttribute("ondoubleclick", sbTaskClickScript.ToString)
'writer.AddAttribute(HtmlTextWriterAttribute.Class, Me.CssClass)
'writer.RenderBeginTag(HtmlTextWriterTag.Div)
'writer.AddAttribute("class", CssClass)
'writer.WriteFullBeginTag("div style='font-family:Verdana;font-size:9pt;width: 100%;color:Black'")
MyBase.RenderPreText(writer)
End Sub
Protected Overrides Sub RenderPostText(ByVal writer As System.Web.UI.HtmlTextWriter)
If (
Me.Depth < 3 And Me.Depth > 0) Then
writer.AddAttribute("class", "con")
End If
writer.WriteEndTag("div")
MyBase.RenderPostText(writer)
End Sub
End Class
Public Enum enumNodeTypes
'---DONT CHANGE THE ENUM VALUES
'---Used for Project-Building-Units Treeview
Project = 0
Building = 1
Wing = 2
Unit = 3
Parking = 5
'---Used for Templates Treeview
TemplateType = 6
PaymentScheduleTemplate = 7
OtherChargesTemplate = 8
ExtraWorkTemplate = 9
AgreementOtherCharges = 10
'---Used for Tasks Treeview
TaskGroup = 31
Task = 4
'------- Added for Highrise Engineering ------------
'-----------------------------------------------------------------------------------
'-- Following are just some random constants which are not used earlier in this enum
'---They are used only for identifying the node type
'---These values are not saved in the database
'Used to identify the Root Node
Root = 999
'---Used to identify dummy nodes in the treeview
Dummy_Materials = 1001
Dummy_Equipments = 1002
Dummy_Labours = 1003
Dummy_QualityChecks = 1004
Dummy_Requisitions = 1005
Dummy_WorkOrders = 1006
Dummy_Dependencies = 1007
'---Used for Labour Treeview
LabourGroup = 41
Labour = 40
'---Used for Material Treeview
MaterialGroup = 51
Material = 50
'---Used for Equipment Treeview
EquipmentGroup = 61
Equipment = 60
'---Used for Quality Treeview
QualityCheckGroup = 71
QualityCheck = 70
'---Used for Task Treeview
Requisition = 80
WorkOrder = 90
'----------Used for Schedule
Dependency = 95
'------------------------------------------------------------------------------------
TenderItemGroup = 101
TenderItem = 102
TenderItemTask = 103
'--------------------------
TenderEnquiryItemGroup = 201
TenderEnquiryItem = 202
End Enum
Public Enum enumCallingApplication
HighriseSales
HighriseEngineering
HighriseTender
End Enum
我使用jQuery應用上下文菜單上的CSS類是'con'的節點,但問題是當我選擇任何節點所有其他鬆散的CSS類。
<script type="text/javascript">
$(function() {
$.contextMenu({
selector: '#divLibraryTreeView .con',
callback: function (key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit": {
name: "Add group",
icon: "add",
callback: function() { document.getElementById('<%= imgbtnAddNewGroup.ClientID %>').click(); }
},
"cut": {
name: "Add task",
icon: "add",
callback: function() { document.getElementById('<%= imgbtnAddNew.ClientID %>').click(); }
},
"cancel": {
name: "Cancel",
icon: "cross",
callback: function() { return true; }
}
}
});
});
</script>