DisguisePerceptron February 2016

Generate TreeView from XML file

I want create TreeView from data source like XML file. Also I need customize visible Name of element.

What I have:

<?xml version="1.0" encoding="UTF-8"?>

<List>


<siteMapNode title="Title1" url="http://example.com/Pages/General.aspx" description="Description1">

   <siteMapNode title="Title2" url="http://example.com/Pages/Base.aspx" description="Description2"/>

</siteMapNode>

<siteMapNode title="Title3" url="http://example.com/Lists/News.aspx" description="Description3"> </siteMapNode>



</List>

And it i can generate:

List
  siteMapNode
     siteMapNode
  siteMapNode

And now what I want get:

List
  Title1
    Title2
  Title3

UPD: I generate treeview like it in .aspx:

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="footerSiteMap.xml"></asp:XmlDataSource>

<asp:TreeView ID="TreeView1" runat="server" DataSourceID="Xmldatasource1" ShowLines="true" ShowCheckBoxes="All">

    <DataBindings>
        <asp:TreeNodeBinding DataMember="{siteMapNode_Id}" TextField="{siteMapNode_Id}" ValueField="{siteMapNode_Id}"  />
        <asp:TreeNodeBinding DataMember="{siteMapNode_Id_0}" TextField="{siteMapNode_Id_0}" ValueField="{siteMapNode_Id_0}" />
        <asp:TreeNodeBinding DataMember="{title}" TextField="{title}" ValueField="{title}" />
        <asp:TreeNodeBinding DataMember="{url}" TextField="{url}" ValueField="{url}" />
        <asp:TreeNodeBinding DataMember="{description}" TextField="{description}" ValueField="{description}" />
    </DataBindings>

</asp:TreeView>

How i can generate it from .aspx.cs ?

Answers


Karthikeyan February 2016

use Attributes to get the value of siteMapNode like,

var attr = node.Attributes["title"];

Post Status

Asked in February 2016
Viewed 1,631 times
Voted 10
Answered 1 times

Search




Leave an answer