Hi,
I have a treeview control with 4 levels of branch in it. Each node is rendered as a template and the template has 2 checkboxes.
I need the tristate cascading check mechanism to apply to these templated nodes. Below is some sample code for this based on a simple two branch level tree.
In a nutshell I would like it so that if the user clicks on the first checkbox for the first parent node then the first checkbox in the two child nodes will also be ticked. If one of them is then unticked, the parent first node should show the tristate status.
The purpose of this is to make various admin tasks quick and simple.
Any thoughts?
Regards,
Jon
I have a treeview control with 4 levels of branch in it. Each node is rendered as a template and the template has 2 checkboxes.
I need the tristate cascading check mechanism to apply to these templated nodes. Below is some sample code for this based on a simple two branch level tree.
In a nutshell I would like it so that if the user clicks on the first checkbox for the first parent node then the first checkbox in the two child nodes will also be ticked. If one of them is then unticked, the parent first node should show the tristate status.
The purpose of this is to make various admin tasks quick and simple.
Any thoughts?
Regards,
Jon
Private Sub GenerateTreeView() |
' parent node |
Dim sampleRadTreeNode As RadTreeNode = New RadTreeNode() |
sampleRadTreeNode.NodeTemplate = New NodeTemplate("Sample 1") |
' child node |
Dim sampleChildRadTreeNode As RadTreeNode = New RadTreeNode() |
sampleChildRadTreeNode.NodeTemplate = New NodeTemplate("Sample 1 Child 1") |
sampleRadTreeNode.Nodes.Add(sampleChildRadTreeNode) |
' child node |
sampleChildRadTreeNode = New RadTreeNode() |
sampleChildRadTreeNode.NodeTemplate = New NodeTemplate("Sample 1 Child 2") |
sampleRadTreeNode.Nodes.Add(sampleChildRadTreeNode) |
uxRadTreeView.Nodes.Add(sampleRadTreeNode) |
' parent node |
sampleRadTreeNode = New RadTreeNode() |
sampleRadTreeNode.NodeTemplate = New NodeTemplate("Sample 2") |
uxRadTreeView.Nodes.Add(sampleRadTreeNode) |
uxRadTreeView.DataBind() |
End Sub |
Class NodeTemplate |
Implements ITemplate |
Public text As String |
Public level As Integer |
Public Sub New(ByVal text As String) |
Me.text = text |
End Sub |
Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn |
Dim table As Table = New Table() |
table.CssClass = "NodeTemplateCSS" |
table.CellPadding = 0 |
table.CellSpacing = 0 |
Dim tableRow As TableRow = New TableRow() |
Dim tableTextCell As TableCell = New TableCell() |
Dim nodeText As Label = New Label() |
nodeText.ID = "ItemLabel" |
nodeText.Text = text |
tableTextCell.Controls.Add(nodeText) |
Dim checkbox1Cell As TableCell = New TableCell() |
Dim checkbox1 As CheckBox = New CheckBox() |
checkbox1.ID = "checkbox1" |
checkbox1Cell.Controls.Add(checkbox1) |
Dim checkbox2Cell As TableCell = New TableCell() |
Dim checkbox2 As CheckBox = New CheckBox() |
checkbox2.ID = "checkbox2" |
checkbox2Cell.Controls.Add(checkbox2) |
tableRow.Cells.Add(tableTextCell) |
tableRow.Cells.Add(checkbox1Cell) |
tableRow.Cells.Add(checkbox2Cell) |
table.Rows.Add(tableRow) |
container.Controls.Add(table) |
End Sub |
End Class |