This is a migrated thread and some comments may be shown as answers.

RadGrid FindControl Not Working

2 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 09 Mar 2011, 10:51 PM
Can't figure out why this bombing out.
It errors out at line 9. The error msg is : "Object reference not set to an instance of an object."
This node is created on Page load. The dropdown is added using "treeNode.Controls.Add"

# 1        If TreeView1.Nodes(0).Checked Then
# 2            Dim arrColors(TreeView1.Nodes(0).Nodes.Count, 2)
# 3
# 4           For int As Integer = 0 To TreeView1.Nodes(0).Nodes.Count - 1
# 5               arrColors(int, 0) = TreeView1.Nodes(0).Nodes(int).Value.Trim
# 6                Dim ddColor As DropDownList = New DropDownList
# 7                ddColor = DirectCast(TreeView1.Nodes(0).Nodes(int).FindControl("dd"), DropDownList)
# 8
# 9                arrColors(int, 1) = ddColor.SelectedValue
# 10
# 11         Next
# 12
# 13        End If

Please Help!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Mar 2011, 09:46 AM
Hello Brad,


I found a documentation on "how to add templates for TreeNode" at runtime.
Adding and Editing Templates at Runtime


And the below documentation shows how to access the control added to node.
Accessing Controls Inside Templates

I hope these links would shed some light on achieving functionality for you.


-Shinu.
0
Brad
Top achievements
Rank 1
answered on 10 Mar 2011, 05:26 PM
I'm not using templatenodes. I'm simply adding the controls at runtime with the following code.

                 '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)

Am I missing something here?
Tags
Grid
Asked by
Brad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brad
Top achievements
Rank 1
Share this question
or