I'm adding nodes to the treeview at page load. Also at the same time I am adding a Label and a DropDown control to the node.
I want to disable the DropDowns for certain nodes based on what node was checked. The Error I'm getting is :
"Object reference not set to an instance of an object."
This is because the the TreeView1.Nodes(0).Nodes(i).Count is 0. But it shouldn't be.
Does anyone know what I'm doing wrong here?
Heres how I am creating the nodes:
For i As Integer = 0 To DsStateDistrictID.Tables(0).Rows.Count - 1
Dim treeNode As New Telerik.Web.UI.RadTreeNode(DsStateDistrictID.Tables(0).Rows(i).Item("DistrictName").ToString)
treeNode.Value = DsStateDistrictID.Tables(0).Rows(i).Item("StateDistrictID").ToString
treeNode.Checkable = True
'Add Label with StateDistrict Name to Node
Dim lbl As Label = New Label
lbl.Text = DsStateDistrictID.Tables(0).Rows(i).Item("DistrictName").ToString
lbl.ID = "lbl" & DsStateDistrictID.Tables(0).Rows(i).Item("StateDistrictID").ToString.Trim
treeNode.Controls.Add(lbl)
'Add Color DropDown to Node
Dim ddColor As DropDownList = New DropDownList
ddColor.ID = "dd" '& DsStateDistrictID.Tables(0).Rows(i).Item("StateDistrictID").ToString.Trim
ddColor = BuildColorDropDown(ddColor)
treeNode.Controls.Add(ddColor)
TreeView1.Nodes(0).Nodes.Add(treeNode)
Next
End If
Heres how I am trying to disable the drop down list:
For i As Integer = 0 To TreeView1.Nodes(0).Nodes.Count - 1
Dim StateDistrictID As String = TreeView1.Nodes(0).Nodes(i).Value.ToString.Trim
Dim ddColor As New DropDownList
ddColor = CType(TreeView1.Nodes(0).Nodes(i).FindControl("dd" & StateDistrictID), DropDownList)
ddColor.Enabled = False
Next
I want to disable the DropDowns for certain nodes based on what node was checked. The Error I'm getting is :
"Object reference not set to an instance of an object."
This is because the the TreeView1.Nodes(0).Nodes(i).Count is 0. But it shouldn't be.
Does anyone know what I'm doing wrong here?
Heres how I am creating the nodes:
For i As Integer = 0 To DsStateDistrictID.Tables(0).Rows.Count - 1
Dim treeNode As New Telerik.Web.UI.RadTreeNode(DsStateDistrictID.Tables(0).Rows(i).Item("DistrictName").ToString)
treeNode.Value = DsStateDistrictID.Tables(0).Rows(i).Item("StateDistrictID").ToString
treeNode.Checkable = True
'Add Label with StateDistrict Name to Node
Dim lbl As Label = New Label
lbl.Text = DsStateDistrictID.Tables(0).Rows(i).Item("DistrictName").ToString
lbl.ID = "lbl" & DsStateDistrictID.Tables(0).Rows(i).Item("StateDistrictID").ToString.Trim
treeNode.Controls.Add(lbl)
'Add Color DropDown to Node
Dim ddColor As DropDownList = New DropDownList
ddColor.ID = "dd" '& DsStateDistrictID.Tables(0).Rows(i).Item("StateDistrictID").ToString.Trim
ddColor = BuildColorDropDown(ddColor)
treeNode.Controls.Add(ddColor)
TreeView1.Nodes(0).Nodes.Add(treeNode)
Next
End If
Heres how I am trying to disable the drop down list:
For i As Integer = 0 To TreeView1.Nodes(0).Nodes.Count - 1
Dim StateDistrictID As String = TreeView1.Nodes(0).Nodes(i).Value.ToString.Trim
Dim ddColor As New DropDownList
ddColor = CType(TreeView1.Nodes(0).Nodes(i).FindControl("dd" & StateDistrictID), DropDownList)
ddColor.Enabled = False
Next