I have a webpage that uses a Treeview.
In the treeview are nodes and i use the Text and Value property, but i need one more. I need one boolean property called IsFile.
I make the Nodes and add them to the tree programmatically.
I have a class Called NavTreeNodes that inherits the TreeNode class and ads this bool.
public class NavTreeNode : TreeNode
{
private bool _IsFile;
public bool IsFile
{
get { return _IsFile; }
set { _IsFile = value; }
}
public NavTreeNode()
{ }
}
And when i make a new TreeNode i use this class.
Everything works until i try to get the data from the treeview in the SelectedNodeChanged on the TreeView function.
protected void treeview_Navigation_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNode node = treeview_Navigation.SelectedNode;
NavTreeNode NNode = node as NavTreeNode;
Response.Write(NNode.IsFile.ToString());
}
I get a “Object reference not set to an instance of an object.” error when i try this.
I cant even get the Value or the Text value using this method.
Create new class that holds your value and IsFile property and put it in Value property of node.
Not sure that solution with serialization is best, but it solves the problem