Hey SodakotaHusker,
Here is the code I am using for the treedisplay
public class TreeDisplay : WebPart, IWebPartField
{
public TreeView _treeView;
public DataTable _table;
public FieldCallback _consumerDelegate = null;
public TreeNode _nodeRoot;
HttpContext _context = HttpContext.Current;
public TreeNode _nodeSelected;
// public bool _bTreeIsLoading = false;
public bool _bDoneOnce = false;
public bool _bIsLoading = false;
public bool _bIsExpanding = false;
public bool _bIsSelected = false;
public int count = 0;
public int _iKey = 0;
public int _iType = 1;
public string _Type = "";
public TreeDisplay()
{
_bIsLoading = true;
_nodeRoot = (TreeNode)null;
string url = "
//string to get the project number
int index = url.IndexOf(".aspx"); //getting the project number from the string
string right = url.Substring(index);
string left = url.Substring(0, index);
int st = left.LastIndexOf("/");
// get the Type:
_Type = left.Substring(st + 1);
if (_Type.IndexOf("proj") == 0)
_Type = "Project";
else if (_Type.IndexOf("mll") == 0)
_Type = "Mill";
else if (_Type.IndexOf("client") == 0)
_Type = "Client";
else if (_Type.IndexOf("sups") == 0)
_Type = "Suppliers";
else if (_Type.IndexOf("equip") == 0)
_Type = "Equipment";
else if (_Type.IndexOf("docs") == 0)
_Type = "Documents";
// get the Key:
string key = url.Substring(url.LastIndexOf("=") + 1);
int result = 1;
if (Int32.TryParse(key, out result))
_iKey = Convert.ToInt32(key);
/// *** Initializing the Tree *** //
_treeView = new TreeView();
_treeView.ImageSet = TreeViewImageSet.XPFileExplorer;
InitializeTreeRoot();
InitializeTree();
_nodeRoot.Selected = true;
_treeView.SelectedNodeStyle.BackColor = System.Drawing.Color.LightGray;
_treeView.SelectedNodeChanged += new EventHandler(_treeView_SelectedNodeChanged);
_treeView.PopulateNodesFromClient = true;
_treeView.TreeNodePopulate += new TreeNodeEventHandler(_treeView_TreeNodePopulate);
Controls.Add(_treeView);
_treeView.SelectedNodeStyle.BackColor = System.Drawing.Color.LightGray;
_treeView.SelectedNodeChanged += new EventHandler(_treeView_SelectedNodeChanged);
_treeView.PopulateNodesFromClient = true;
_treeView.TreeNodePopulate += new TreeNodeEventHandler(_treeView_TreeNodePopulate);
count++;
_bIsLoading = false;
}
//Event Handler for loading the children when a node is clicked
void _treeView_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
string ParentKey = "";
TreeNode currentNode = e.Node;
//currentNode.Select();
TreeNode ParentNode = e.Node.Parent;
currentNode.ChildNodes.Clear();
if (currentNode.Text.IndexOf("Mill") == 0)
{
currentNode.ChildNodes.Add(new TreeNode("ChildMill"));
}
if (currentNode.Text.IndexOf("Project") == 0)
{
// ParentKey = ParentNode.Value.Substring(ParentNode.Value.IndexOf("||"), 1);
currentNode.ChildNodes.Add(new TreeNode("Child"));
}
else
{
currentNode.ChildNodes.Add(new TreeNode("Child"));
}
}
This is my main TreeView class and the event handler when the node is clicked to load the children of that clicked node. I need to get the parent of the node clicked in order to load the children of that node but when I try to get it using e.Node.Parent I am getting NULL value but the depth is 2 for that node. I am confused. The one thing I observed is my constructor for TreeDisplay is being called when a PostBack is being made, I tried checking if it is a postback or not using IsNotPostBack but it is throwing an error that i cannot use isnotpostback there. do we need to load the tree everytime the page refreshs? Can it be the reason why my clicked node parent is null? Can you please tell me what I am doing wrong?
Thanks,
Ram