Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual studio 2005 Question

Status
Not open for further replies.

cplsplsprogrammer

Programmer
Apr 18, 2005
42
US
Hello All,

I am using a tree structure in my webpage. I load the basic tree structure on page load and wanted to load the children of those nodes on the fly and so I used the eventhandler but after I catch the event and get the node and try to find the parent of the node it is givining me NULL value but it is showing the depth correctly I think the parent node for only root node will be null. Can anyone tell me if I have enable any feature or anything that I am missing.

Thanks,
Ram
 
There is nothing that needs to be enabled. I hate to say it but this seems to be one of those problems that you have to post your code for us to help you. I believe that you just are not accessing the object correctly
 
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
 
Is your constructor is being invoked in the page load event?

If so, you would want to use your isPostback condition there to prevent it from firing.
Your note mentions isNotPostBack. If you are literally trying to use that, you will have a problem since the property is simply IsPostBack and the negative check would be for !IsPostBack
Probably you were just paraphrasing so the property is not the issue??
 
Hello Husker,

Yes my constructor is being invoked in the page load event and yes you were right, I was just paraphrasing it. I used !IsPostBack...

I am trying to build a sharepiont webpart so not sure if I can use IsPostBack property on there. Do you know of anyway that I can use to make it not call the constructor on PostBack?

Thanks,
Ram
 
I have never worked with webparts. Did you post this question on the ASP.Net forum?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top