I have to do everything at runtime; tree nodes vary by user. I used example code to apply node templates... works as expected.
When I select a node (and get the postback) the templates are not applied. Then I select a node again (and get the postback), the template is applied... it just toggles back and forth. Code is below....
When I select a node (and get the postback) the templates are not applied. Then I select a node again (and get the postback), the template is applied... it just toggles back and forth. Code is below....
Private Sub GetAccountProducts(ByVal AccountID As String, ByVal Category As String, ByRef node As Telerik.Web.UI.RadTreeNode) |
Try |
Dim objCom As New SqlClient.SqlCommand |
Dim objDA As New SqlClient.SqlDataAdapter |
Dim objDT As New DataTable |
objCom.Connection = objSLXCon |
objCom.CommandText = "select ap.ACCOUNTPRODUCTID, ap.SERIALNUMBER, ap.PRODUCTNAME " & _ |
"from accountproduct ap inner join product p on ap.productid = p.productid " & _ |
"where ap.accountid = '" & AccountID & "' and p.family = '" & Category & "' " & _ |
"and ap.accountproductid in (select accountproductid from ADVANTAGEVISIONACCESS where contactid = '" & Request.Cookies("UserID").Value & "')" |
objDA.SelectCommand = objCom |
objDA.Fill(objDT) |
For Each dr As DataRow In objDT.Rows |
Dim AssetNode As New Telerik.Web.UI.RadTreeNode() |
AssetNode.Text = dr.Item("SERIALNUMBER").ToString |
AssetNode.Value = dr.Item("ACCOUNTPRODUCTID").ToString |
AssetNode.Attributes.Add("Level", "Asset") |
AssetNode.Attributes.Add("Model", dr.Item("PRODUCTNAME")) |
AssetNode.NavigateUrl = "Assets.aspx?Level=Asset&AssetID=" & dr.Item("ACCOUNTPRODUCTID").ToString |
Dim template As New AssetTemplate() |
template.InstantiateIn(AssetNode) |
node.Nodes.Add(AssetNode) |
Next |
Catch ex As Exception |
End Try |
End Sub |
Class AccountTemplate |
Implements ITemplate |
Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn |
Dim label1 As New Label() |
Dim node As RadTreeNode = DirectCast(container, RadTreeNode) |
label1.ID = "accountnamelabel" |
label1.Text = node.Text |
label1.ForeColor = Drawing.Color.Black |
container.Controls.Add(label1) |
End Sub |
End Class |
Class ContactTemplate |
Implements ITemplate |
Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn |
Dim label1 As New Label() |
Dim node As RadTreeNode = DirectCast(container, RadTreeNode) |
label1.ID = "alllocationslabel" |
label1.Text = node.Text |
label1.ForeColor = Drawing.Color.Black |
container.Controls.Add(label1) |
End Sub |
End Class |
Class FamilyTemplate |
Implements ITemplate |
Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn |
Dim label1 As New Label() |
Dim node As RadTreeNode = DirectCast(container, RadTreeNode) |
label1.ID = "familynamelabel" |
label1.Text = node.Text |
label1.ForeColor = Drawing.Color.Black |
container.Controls.Add(label1) |
End Sub |
End Class |
Class AssetTemplate |
Implements ITemplate |
Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn |
Dim label1 As New Label() |
Dim label2 As New Label() |
Dim node As RadTreeNode = DirectCast(container, RadTreeNode) |
label1.ID = "assetnamelabel" |
label1.Text = node.Attributes("Model") |
label1.ForeColor = Drawing.Color.Black |
container.Controls.Add(label1) |
label2.ID = "assetseriallabel" |
label2.Text = " - SN: " & node.Text |
label2.ForeColor = Drawing.Color.Black |
container.Controls.Add(label2) |
End Sub |
End Class |