XML Data type in SQL Server 2005 and treeview

Last post 07-03-2008 5:41 AM by Samu Zhang - MSFT. 2 replies.

Sort Posts:

  • XML Data type in SQL Server 2005 and treeview

    06-30-2008, 12:00 AM
    • Loading...
    • pizzamaker74
    • Joined on 09-26-2006, 12:31 AM
    • Melbourne Australia
    • Posts 83

    I would like to put together a treeview where the parent node is sourced from a text (nvarchar data type) field (column) in SQL Server 2005 and the child XML data for the second and subsequent nodes are sourced from an XML Datatype field in SQL Server 2005.

     What I'm trying to achieve is that the XML is only parsed if the user expands the "parent" node.

     ie

    User1(nvarchar)

    User2(nvarchar)

    User3(nvarchar)

    User clicks on User 3, and the XML Data in the XML data type column on that row is parsed into a treeview which can expand to however many node depths is required when expanded.

    If anyone can point me to an implementation of this or a post which will help me I'd appreciate greatly!

     

  • Re: XML Data type in SQL Server 2005 and treeview

    06-30-2008, 7:26 PM
    • Loading...
    • pizzamaker74
    • Joined on 09-26-2006, 12:31 AM
    • Melbourne Australia
    • Posts 83

    I'm at the stage where I have the parent node, and the onTreeNodePopulate event triggering another database lookup for that record retreiving the XML data, and then putting it into a string;

    XmlDatasource1.Data = strUserXMLData

    All I need now is for this XML to be attached as child node(s) of the selected Node.

    I want to ignore the root of the XML string and to only add the child and leaf nodes to the treeview if possible (oh of course its possible I hear you say..!)...he he.

    Any ideas?...

  • Re: XML Data type in SQL Server 2005 and treeview

    07-03-2008, 5:41 AM
    Answer

    Hi pizzamaker74 ,

    You can put one TreeView control on page and write some code in selectednodechanged event.

    See one sample,

     

        <form id="form1" runat="server">
        <div>
        
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        
        </div>
        
        
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TreeView ID="TreeView1" runat="server" 
            onselectednodechanged="TreeView1_SelectedNodeChanged">
                </asp:TreeView>
            </ContentTemplate>
        </asp:UpdatePanel>
        
        
        </form>
      
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    TreeNode parentnode = new TreeNode("click me", "01");
                    this.TreeView1.Nodes.Add(parentnode);
                }
                //this.ToolkitScriptManager1.r
            }
    
            protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
            {
                TreeNode sel = this.TreeView1.SelectedNode;
                string val = sel.Value;
    
                TreeNode child1 = new TreeNode("i'm child1", "0101");
                sel.ChildNodes.Add(child1);
    
                TreeNode child2 = new TreeNode("i'm child2", "0102");
                sel.ChildNodes.Add(child2);
            }

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter