Hi,
I have a treeview that I'm using to provide a set of controls on each node. There is the normal node text, a textbox and a checkbox. I've got it all working except for reading the data back. My routine can't use Node.FindControl to find any of the controls that I've created. Some relevant snippets of code are shown below.
I've read that I need to reallocate the template to the nodes on the ajax callback. How do I go about this? (current update code at the bottom).
Regards,
Jon
I have a treeview that I'm using to provide a set of controls on each node. There is the normal node text, a textbox and a checkbox. I've got it all working except for reading the data back. My routine can't use Node.FindControl to find any of the controls that I've created. Some relevant snippets of code are shown below.
I've read that I need to reallocate the template to the nodes on the ajax callback. How do I go about this? (current update code at the bottom).
Regards,
Jon
| 'CODE FOR GENERATING THE TREE |
| uxRadTreeView.DataTextField = "LocationCombo" |
| uxRadTreeView.DataFieldID = "AuditEntryID" |
| uxRadTreeView.DataValueField = "AuditEntryID" |
| uxRadTreeView.DataSource = groups |
| uxRadTreeView.DataBind() |
| Dim template As NodeTemplate = New NodeTemplate() |
| template._InEditMode = _InEditMode |
| For Each node As RadTreeNode In uxRadTreeView.GetAllNodes() |
| template.InstantiateIn(node) |
| node.Expanded = True |
| node.DataBind() |
| Next |
| ' TEMPLATE CODE |
| Class NodeTemplate |
| Implements ITemplate |
| Public _InEditMode As Boolean |
| Public Sub New() |
| End Sub |
| Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn |
| Dim uxLocationCombo As Label = New Label() |
| uxLocationCombo.ID = "uxLocationCombo" |
| uxLocationCombo.Width = 300 |
| AddHandler uxLocationCombo.DataBinding, AddressOf nodeText_DataBinding |
| container.Controls.Add(uxLocationCombo) |
| If _InEditMode Then |
| Dim uxScore As RadNumericTextBox = New RadNumericTextBox() |
| uxScore.ID = "uxScore" |
| uxScore.Enabled = True |
| uxScore.Width = 60 |
| uxScore.MinValue = 1 |
| uxScore.MaxValue = 5 |
| uxScore.ShowSpinButtons = True |
| uxScore.NumberFormat.DecimalDigits = 0 |
| AddHandler uxScore.DataBinding, AddressOf uxScore_DataBinding |
| container.Controls.Add(uxScore) |
| Else |
| Dim uxScore As Label = New Label() |
| uxScore.ID = "uxScore" |
| uxScore.Enabled = True |
| uxScore.Width = 60 |
| AddHandler uxScore.DataBinding, AddressOf uxScoreLabel_DataBinding |
| container.Controls.Add(uxScore) |
| End If |
| Dim uxNotScored As CheckBox = New CheckBox() |
| uxNotScored.ID = "uxNotScored" |
| uxNotScored.Enabled = _InEditMode |
| uxNotScored.Width = 60 |
| AddHandler uxNotScored.DataBinding, AddressOf uxNotScoredCheckbox_DataBinding |
| container.Controls.Add(uxNotScored) |
| End Sub |
| Private Sub uxScoreLabel_DataBinding(ByVal sender As Object, ByVal e As EventArgs) |
| Try |
| Dim target As Label = DirectCast(sender, Label) |
| Dim node As RadTreeNode = DirectCast(target.BindingContainer, RadTreeNode) |
| target.Text = node.Attributes("Score").ToString() |
| 'target.Attributes("onClick") = "onNodeClick(" & node.Attributes("DocumentTypeID").ToString() & ");" |
| Catch ex As Exception |
| End Try |
| End Sub |
| Private Sub uxScore_DataBinding(ByVal sender As Object, ByVal e As EventArgs) |
| Try |
| Dim target As RadNumericTextBox = DirectCast(sender, RadNumericTextBox) |
| Dim node As RadTreeNode = DirectCast(target.BindingContainer, RadTreeNode) |
| target.Text = node.Attributes("Score").ToString() |
| 'target.Attributes("onClick") = "onNodeClick(" & node.Attributes("DocumentTypeID").ToString() & ");" |
| Catch ex As Exception |
| End Try |
| End Sub |
| Private Sub uxNotScoredCheckbox_DataBinding(ByVal sender As Object, ByVal e As EventArgs) |
| Try |
| Dim target As CheckBox = DirectCast(sender, CheckBox) |
| Dim node As RadTreeNode = DirectCast(target.BindingContainer, RadTreeNode) |
| target.Checked = CBool(node.Attributes("NotScored").ToString()) |
| 'target.Attributes("onClick") = "onNodeClick(" & node.Attributes("AuditEntryID").ToString() & ");" |
| Catch ex As Exception |
| End Try |
| End Sub |
| Private Sub nodeText_DataBinding(ByVal sender As Object, ByVal e As EventArgs) |
| Try |
| Dim target As Label = DirectCast(sender, Label) |
| Dim node As RadTreeNode = DirectCast(target.BindingContainer, RadTreeNode) |
| target.Text = node.Attributes("LocationCombo").ToString() |
| 'target.Attributes("onClick") = "onNodeClick(" & node.Attributes("DocumentTypeID").ToString() & ");" |
| Catch ex As Exception |
| End Try |
| End Sub |
| End Class |
| ' CODE IN THE UPDATE BUTTON CALLBACK |
| For Each node As RadTreeNode In uxRadTreeView.Nodes |
| i += 1 |
| idArray(i) = node.Value |
| scoreArray(i) = DirectCast(node.TemplateControl.FindControl("uxScore"), RadNumericTextBox).Value.ToString() |
| If DirectCast(node.TemplateControl.FindControl("uxNotScored"), CheckBox).Checked Then |
| noScoreArray(i) = "1" |
| Else |
| noScoreArray(i) = "0" |
| End If |
| Next |