Home - Forums-.NET - FlyTreeView (ASP.NET) - ftvClient_PopulateNodes method

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

ftvClient_PopulateNodes method
Link Posted: 30-Mar-2009 15:59
Hi, I have used the FlyTreeView to display the tree nodes. I have a search textbox to display specific nodes for different employees, however, I have problems to populate the nodes. It throwed out the exceptions and I found the parameter e in this method is null. (In fact, e.Node is null). Could you please help me about this? My control page: [code] <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ClientTreeView.ascx.cs" Inherits="Admin_Controls_ClientTreeView" %> <%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls" TagPrefix="NineRays" %> <%@ Register Src="~/Service/EmployeeSearch.ascx" TagName="EmployeeSearch" TagPrefix="uc1" %>  
function flyTreeView2_OnDrop(target, event) { // target - instance of CFlyTreeNode or CFlyTreeView (root zone) which is the target of drop operation // increas the New Node NUM //IncreaseDragFromNumber(); return confirm('Are you sure to move this project?'); } function flyTreeView1_OnDragStart(node) { // empty - just example } function flyTreeView2_OnDragOver(target) { // target - instance of CFlyTreeNode or CFlyTreeView (root zone) which is currently under the mouse pointer } function flyTreeView2_OnDragOut(target) { // target - instance of CFlyTreeNode or CFlyTreeView (root zone) which was under the mouse pointer } // Helper function to increase New Node number. var dragFromNumber = 1; function IncreaseDragFromNumber() { // flytreeview_dragObject.state values: // 0 - deny // 1 - move // 2 - copy // we increase New Node number only when the node is MOVED if (!(flytreeview_dragObject.value instanceof CFlyTreeNode) && flytreeview_dragObject.state == 1) dragFrom.innerHTML = "New Node (" + (dragFromNumber ++) + ")"; } [/code] And my cs page: [code] using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Generic; using SSS.MIS.BLL.Managers; using SSS.MIS.Domain.DomainObjects; using NineRays.WebControls; using SSS.MIS.Domain.DomainObjects.Clients; using SSS.MIS.Domain.DomainObjects.Projects; using SSS.MIS.GUI.ClientTreeView; using SSS.MIS.GUI; using SSS.MIS.Domain.DomainObjects.Employees; public partial class Admin_Controls_ClientTreeView : BaseControlPage { #region Private Members and Properties private ClientManager clientManager = new ClientManager(); private ProjectManager projectManager = new ProjectManager(); private TaskManager taskManager = new TaskManager(); #region Delegate public delegate void SelectDelegate(NodeSelectEventArgs e); public event SelectDelegate Seleted; #endregion //Alan 2009-03-27 private int searchEmployeeId; //public int SearchEmployeeId //{ // get { return searchEmployeeId; } // set { searchEmployeeId = value; } //} //Alan 2009-03-27 public NodeType NodeExpandLevel { get { if (ViewState["NodeExpandLevel"] != null) { return (NodeType)Enum.Parse(typeof(NodeType), ViewState["NodeExpandLevel"].ToString()); } else { return NodeType.Task; } } set { ViewState["NodeExpandLevel"] = value; } } public FlyTreeView curTree { get { return ftvClient; } } #endregion #region event handles protected void Page_Load(object sender, EventArgs e) { BindClients(); //ftvClient.SelectedNode = e. //ftvClient_SelectedNodeChanged(sender, (NineRays.WebControls.SelectedNodeChangedEventArgs)e); //if (!IsPostBack && ftvClient.Nodes.Count <= 0) //{ // ICollection clients = clientManager.GetRootClients(); // AddClients(ftvClient.Nodes, clients); //} } /// /// This will be called automatically to fulfill populate nodes within expanded status. /// /// /// protected void ftvClient_PopulateNodes(object sender, FlyTreeNodeEventArgs e) { //alan //if (e.Node != null) //{ // e.Node = ftvClient.pos //} e.Node.ChildNodes.Clear(); if (e.Node.NodeTypeID == NodeType.Client.ToString()) { //add subclients ICollection subClients; if (searchEmployeeId == 0) subClients = clientManager.GetSubClients(Convert.ToInt32(e.Node.Value)); else subClients = clientManager.GetSubClientsByEmployeeId(Convert.ToInt32(e.Node.Value), searchEmployeeId); AddClients(e.Node.ChildNodes, subClients); if (NodeExpandLevel.GetHashCode() >= NodeType.Project.GetHashCode
Link Posted: 31-Mar-2009 00:49
You should probably bind nodes only at the initial page load (Page_Load method):
if (!IsPostBack)
{
    BindClients();
}

Alternatively, if you really need to rebind treeview every time, then check for IsCallback instead

if (!IsCallback)
{
    BindClients();
}