Hi Guys,
Im not so sure why this code throws out an casting error since this feature can be implemented in vs 2003 but not in vs express 2005..
Basically i have a class which is inheriting the TreeNode class
Then, somewhere in the aspx page, im using the above class to create a treenode
Everything works fine..But when i try to retrieve the value of GroupName attached to each node using the event "TreeNodePopulate", i get some casting error. It seems like its not possible to cast the TreeNode Class to its subclass to retrieve its member values (GroupName)
Error: Unable to cast object of type System.Web.UI.WebControls.TreeNode to type DGTree.
Im not sure why, but this same approach works in the .net 2003, but no idea why it doesnt work in express edition 2005, am i missing something?
Im not so sure why this code throws out an casting error since this feature can be implemented in vs 2003 but not in vs express 2005..
Basically i have a class which is inheriting the TreeNode class
Code:
public class DGTree : TreeNode
{
private string groupName;
public DGTree()
{}
public DGTree(string groupName, string text)
{
this.GroupName = groupName;
this.Text = text;
this.NavigateUrl = "index.aspx";
this.PopulateOnDemand = true;
}
public string GroupName
{
get
{
return groupName;
}
set
{
groupName = value;
}
}
}
Then, somewhere in the aspx page, im using the above class to create a treenode
Code:
DGTree parent = new DGTree("CAnalysis", "Fabrication");
TreeView1.Nodes.Add(parent);
DGTree parent1 = new DGTree("CAnalysis", "Assembly");
TreeView1.Nodes.Add(parent1);
Everything works fine..But when i try to retrieve the value of GroupName attached to each node using the event "TreeNodePopulate", i get some casting error. It seems like its not possible to cast the TreeNode Class to its subclass to retrieve its member values (GroupName)
Error: Unable to cast object of type System.Web.UI.WebControls.TreeNode to type DGTree.
Code:
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
DGTree node = (DGTree)e.Node;
populateChildren(node.GroupName.ToString());
}
Im not sure why, but this same approach works in the .net 2003, but no idea why it doesnt work in express edition 2005, am i missing something?
Last edited by a moderator: