locked
Problems with TreeView and binding to XML. RRS feed

  • Question

  • User1981482205 posted

    Hello,

    I have the following form:
    http://www.pastebin.ca/553377

     with the following codefile:
    http://www.pastebin.ca/553380 

    As you can see, the XML has 5 nodes...

    However, when I execute this, only the first four are loaded into the treeview.

    I thought it was my cache, browser etc.. so I rebooted, cleaned the cache, ran a disk cleaner etc and I keep getting only 4 in the treeview and not 5

    In the original code, the XML is created by a function that executes a SP.

    Can any one else reproduce this? can any one tell me what is wrong?

     Thanks,

    Wachaca 

    Saturday, June 9, 2007 2:19 PM

Answers

  • User945078486 posted

    Hello,

    I added this

    protected void Page_Load(object sender, EventArgs e)
        {
            LoadRootPolizaLineaNegociosTreeView();

        }
        private void LoadRootPolizaLineaNegociosTreeView()
        {

            XmlDataSource xdsLineaNegociosTree = new XmlDataSource();
            XmlDocument Xml = new XmlDocument();
            Xml.LoadXml(@"<ROOT>" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2175316\" ID_LINEA_NEGOCIO=\"Mi Linea AA\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2175316)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2175319\" ID_LINEA_NEGOCIO=\"Mi Linea AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2175319)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2200700\" ID_LINEA_NEGOCIO=\"aaa\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2200700)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2200939\" ID_LINEA_NEGOCIO=\"h2test\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2200939)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2201183\" ID_LINEA_NEGOCIO=\"test AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2201183)\" />" +
                 "<H2_LINEA_NEGOCIO ID_ENTITY=\"2201183\" ID_LINEA_NEGOCIO=\"test AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2201183)\" />" +
                "</ROOT>");
            int ParentNodesCount = Xml.SelectNodes(@"ROOT/H2_LINEA_NEGOCIO").Count;
            if (ParentNodesCount > 0)
            {
                xdsLineaNegociosTree.Data = Xml.OuterXml;
                tvPolizaLineaNegocios.Style["display"] = "block";
            }
            else
            {
                xdsLineaNegociosTree.Data = "<ROOT/>";
            }

            xdsLineaNegociosTree.XPath = @"ROOT/H2_LINEA_NEGOCIO";

            tvPolizaLineaNegocios.Nodes.Clear();
            tvPolizaLineaNegocios.DataSource = xdsLineaNegociosTree;
            TreeNodeBinding treeNodeBinding = new TreeNodeBinding();
            treeNodeBinding.DataMember = "H2_LINEA_NEGOCIO";
            treeNodeBinding.ValueField = "ID_ENTITY";
            treeNodeBinding.TextField = "ID_LINEA_NEGOCIO";
            treeNodeBinding.NavigateUrlField = "NAVIGATE_URL";
            tvPolizaLineaNegocios.DataBindings.Add(treeNodeBinding);
            tvPolizaLineaNegocios.DataBind();
            return;
        }

    it works and display <script type=text/javascript> <!-- var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } // --> </script> <script src="/ClipBoardTest/WebResource.axd?d=8_2RWKHY1PZPnZRSfCxOPg2&t=633082537532338489" type=text/javascript mce_src="/ClipBoardTest/WebResource.axd?d=8_2RWKHY1PZPnZRSfCxOPg2&t=633082537532338489"></script> <script src="/ClipBoardTest/WebResource.axd?d=mxdVzh0mYgheP7QI4PFdPQ2&t=633082537532338489" type=text/javascript mce_src="/ClipBoardTest/WebResource.axd?d=mxdVzh0mYgheP7QI4PFdPQ2&t=633082537532338489"></script> <script> <!-- function TreeView_PopulateNodeDoCallBack(context,param) { WebForm_DoCallback(context.data.treeViewID,param,TreeView_ProcessNodeData,context,TreeView_ProcessNodeData,false); } // --> </script>

    Mi Linea AA
     Mi Linea AB
     aaa
     h2test
     test AB
     test AB

    Hope it helps,

    <FORM id=form1 name=form1 action=treeViewTest.aspx method=post>
    Jessica
    </FORM>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 14, 2007 1:46 AM

All replies

  • User1981482205 posted

    I have a stop at the line with the code
    tvPolizaLineaNegocios.DataBind();

    After this point the
    tvPolizaLineaNegocios.Nodes.Count is always equal to 4.

     After I reboot my computer, it is "fixed" and I see 5.. but If I modify the XML I have to reboot to  see the changes... any idea?
    Running XP with

     Microsoft Visual Studio 2005
     Version 8.0.50727.762  (SP.050727-7600)
     Microsoft .NET Framework
     Version 2.0.50727

    Thanks


     

    Saturday, June 9, 2007 3:25 PM
  • User945078486 posted

    Hello,

    I just cut and paste the code to my application and it works. I got 5 nodes loaded in my TreeView

     <form id="form1" runat="server">
        <div>
            <asp:TreeView ID="tvPolizaLineaNegocios" runat="server">
            </asp:TreeView>
       
        </div>
        </form>

    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.Xml;

    public partial class treeViewTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadRootPolizaLineaNegociosTreeView();

        }
        private void LoadRootPolizaLineaNegociosTreeView()
        {

            XmlDataSource xdsLineaNegociosTree = new XmlDataSource();
            XmlDocument Xml = new XmlDocument();
            Xml.LoadXml(@"<ROOT>" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2175316\" ID_LINEA_NEGOCIO=\"Mi Linea AA\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2175316)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2175319\" ID_LINEA_NEGOCIO=\"Mi Linea AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2175319)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2200700\" ID_LINEA_NEGOCIO=\"aaa\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2200700)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2200939\" ID_LINEA_NEGOCIO=\"h2test\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2200939)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2201183\" ID_LINEA_NEGOCIO=\"test AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2201183)\" />" +
                "</ROOT>");
            int ParentNodesCount = Xml.SelectNodes(@"ROOT/H2_LINEA_NEGOCIO").Count;
            if (ParentNodesCount > 0)
            {
                xdsLineaNegociosTree.Data = Xml.OuterXml;
                tvPolizaLineaNegocios.Style["display"] = "block";
            }
            else
            {
                xdsLineaNegociosTree.Data = "<ROOT/>";
            }

            xdsLineaNegociosTree.XPath = @"ROOT/H2_LINEA_NEGOCIO";

            tvPolizaLineaNegocios.Nodes.Clear();
            tvPolizaLineaNegocios.DataSource = xdsLineaNegociosTree;
            TreeNodeBinding treeNodeBinding = new TreeNodeBinding();
            treeNodeBinding.DataMember = "H2_LINEA_NEGOCIO";
            treeNodeBinding.ValueField = "ID_ENTITY";
            treeNodeBinding.TextField = "ID_LINEA_NEGOCIO";
            treeNodeBinding.NavigateUrlField = "NAVIGATE_URL";
            tvPolizaLineaNegocios.DataBindings.Add(treeNodeBinding);
            tvPolizaLineaNegocios.DataBind();
            return;
        }

    }

    I am using windows 2003 server and VS2005

    Jessica

    Monday, June 11, 2007 10:52 PM
  • User1981482205 posted

    Hello,

    Thanks for your reply.

    After you load the 5 nodes, please add another line to the XML structure, and see if it loads 6.

    I have tried it on 3 machines, and none show the newly added node.

    Thanks

     

    Tuesday, June 12, 2007 3:24 PM
  • User945078486 posted

    Hello,

    I added this

    protected void Page_Load(object sender, EventArgs e)
        {
            LoadRootPolizaLineaNegociosTreeView();

        }
        private void LoadRootPolizaLineaNegociosTreeView()
        {

            XmlDataSource xdsLineaNegociosTree = new XmlDataSource();
            XmlDocument Xml = new XmlDocument();
            Xml.LoadXml(@"<ROOT>" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2175316\" ID_LINEA_NEGOCIO=\"Mi Linea AA\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2175316)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2175319\" ID_LINEA_NEGOCIO=\"Mi Linea AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2175319)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2200700\" ID_LINEA_NEGOCIO=\"aaa\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2200700)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2200939\" ID_LINEA_NEGOCIO=\"h2test\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2200939)\" />" +
                "<H2_LINEA_NEGOCIO ID_ENTITY=\"2201183\" ID_LINEA_NEGOCIO=\"test AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2201183)\" />" +
                 "<H2_LINEA_NEGOCIO ID_ENTITY=\"2201183\" ID_LINEA_NEGOCIO=\"test AB\" NAVIGATE_URL=\"javascript:LoadLineaNegocioData(2201183)\" />" +
                "</ROOT>");
            int ParentNodesCount = Xml.SelectNodes(@"ROOT/H2_LINEA_NEGOCIO").Count;
            if (ParentNodesCount > 0)
            {
                xdsLineaNegociosTree.Data = Xml.OuterXml;
                tvPolizaLineaNegocios.Style["display"] = "block";
            }
            else
            {
                xdsLineaNegociosTree.Data = "<ROOT/>";
            }

            xdsLineaNegociosTree.XPath = @"ROOT/H2_LINEA_NEGOCIO";

            tvPolizaLineaNegocios.Nodes.Clear();
            tvPolizaLineaNegocios.DataSource = xdsLineaNegociosTree;
            TreeNodeBinding treeNodeBinding = new TreeNodeBinding();
            treeNodeBinding.DataMember = "H2_LINEA_NEGOCIO";
            treeNodeBinding.ValueField = "ID_ENTITY";
            treeNodeBinding.TextField = "ID_LINEA_NEGOCIO";
            treeNodeBinding.NavigateUrlField = "NAVIGATE_URL";
            tvPolizaLineaNegocios.DataBindings.Add(treeNodeBinding);
            tvPolizaLineaNegocios.DataBind();
            return;
        }

    it works and display <script type=text/javascript> <!-- var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } // --> </script> <script src="/ClipBoardTest/WebResource.axd?d=8_2RWKHY1PZPnZRSfCxOPg2&t=633082537532338489" type=text/javascript mce_src="/ClipBoardTest/WebResource.axd?d=8_2RWKHY1PZPnZRSfCxOPg2&t=633082537532338489"></script> <script src="/ClipBoardTest/WebResource.axd?d=mxdVzh0mYgheP7QI4PFdPQ2&t=633082537532338489" type=text/javascript mce_src="/ClipBoardTest/WebResource.axd?d=mxdVzh0mYgheP7QI4PFdPQ2&t=633082537532338489"></script> <script> <!-- function TreeView_PopulateNodeDoCallBack(context,param) { WebForm_DoCallback(context.data.treeViewID,param,TreeView_ProcessNodeData,context,TreeView_ProcessNodeData,false); } // --> </script>

    Mi Linea AA
     Mi Linea AB
     aaa
     h2test
     test AB
     test AB

    Hope it helps,

    <FORM id=form1 name=form1 action=treeViewTest.aspx method=post>
    Jessica
    </FORM>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 14, 2007 1:46 AM