locked
How to code a XML file with the Hyperlinks RRS feed

  • Question

  • User-830563764 posted

    How do I code a XML file for a TreeView control with the HyperLinks added into the tags.
    For example, the code below showed an error on <asp:

    <CEPProvider>
       <All><asp:HyperLink CSSclass="nav" runat+"server" ...NavigateUrl="  "..</All>
    ;;;
    </CEPProvider>

    Friday, July 15, 2016 7:05 PM

Answers

  • User-2057865890 posted

    Hi wonjartran,

    You could use the NavigateUrl property to specify the URL to bind to the NavigateUrl property of a TreeNode object.

    Sample

    <div>
                <h3>TreeViewBinding Example</h3>
    
                <!-- Set the Text, ImageUrl, ImageToolTip, -->
                <!-- NavigateUrl, Value, and ToolTip       -->
                <!-- properties of a TreeNodeBinding       -->
                <!-- object declaratively.                 -->
                <asp:TreeView ID="BookTreeView"
                    DataSourceID="BookXmlDataSource"
                    Target="_blank"
                    runat="server">
    
                    <DataBindings>
                        <asp:TreeNodeBinding DataMember="Books"
                            Depth="0"
                            TextField="Text" />
                        <asp:TreeNodeBinding DataMember="Book"
                            Depth="1"
                            Text="Book Title"
                            ImageUrl="Image.jpg"
                            ImageToolTip="Book Image"
                            NavigateUrl="http://www.microsoft.com"
                            Value="BookID"
                            ToolTip="Book Information" />
                        <asp:TreeNodeBinding DataMember="Description"
                            Depth="2"
                            TextField="Text" />
                        <asp:TreeNodeBinding DataMember="Price"
                            Depth="2"
                            TextField="Value" />
                    </DataBindings>
    
                </asp:TreeView>
    
                <asp:XmlDataSource ID="BookXmlDataSource"
                    DataFile="Booklist.xml"
                    runat="server"></asp:XmlDataSource>
    
            </div>

     XML data

    <Books Text="Books List">
      <Book Text="Book Title One"
          Value="1"
          Image="Bookimage1.jpg"
          ImageToolTip="Book 1 Photo"
          Nav="http://www.microsoft.com"
          Tip="Book Title 1">
        <Description Text="Book Description">
        </Description>
        <Price Value="$1.99">
        </Price>
        <Author Text="Author Name"
            Value="LastName"
            Image="Authorimage1.jpg"
            Nav="http://www.microsoft.com"
            Tip="Author Name">
        </Author>
      </Book>
      <Book Text="Book Title Two"
          Value="2"
          Image="Bookimage2.jpg"
          ImageToolTip="Book 2 Photo"
          Nav="http://www.microsoft.com"
          Tip="Click Me">
        <Description Text="Book Description">
        </Description>
        <Price Value="$2.99">
        </Price>
        <Author Text="Author Name"
            Value="LastName"
            Image="Authorimage2.jpg"
            Nav="http://www.microsoft.com"
            Tip="Author Name">
        </Author>
      </Book>
    </Books>
    

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 18, 2016 5:53 AM
  • User603616845 posted

    Hi,

    How to code a XML file with the Hyperlinks

    I believe, you are just wondering for TreeView Menu which get the data from xml file and displayed as link.

    You can just follow these steps to create such type of menu.

    • Add an XmlDataSource control to the page and set its DataFile property to the name of the XML File
    • Then add a TreeView control and set its DataSourceID property to the ID of the XmlDataSource control.
    • Then map the nodes and their attributes in the XML file to the TreeView nodes by declaring the asp:TreeNodeBinding elements as part of the TreeView declaration

    XML File

    <?xmlversion='1.0'?>
    <!-- This file represents a fragment of a Categories inventory database -->
    <Categories>
    <CategoryID="1" Name="Beverages">
    <DescriptionValue="Soft drinks, coffees, teas, beers, and ales"/>
    </Category>
    <CategoryID="2" Name="Condiments">
    <DescriptionValue="Sweet and savory sauces, relishes, spreads, and
    seasonings"/>
    </Category>
    <CategoryID="3" Name="Confections">
    <DescriptionValue="Desserts, candies, and sweet breads"/>
    </Category>
    <CategoryID="4" Name="Dairy Products">
    <DescriptionValue="Cheeses"/>
    </Category>
    </Categories>

    and last you can bind this xml file data to xmldatasource of the treeview.

    <%@ PageLanguage="C#"%>
    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
     
    <htmlxmlns="http://www.w3.org/1999/xhtml">
    <headrunat="server">
    <title> Binding TreeView Control with an XML File</title>
    </head>
    <body>
    <formid="form1"runat="server">
    <div>
    <asp:TreeView ExpandImageUrl="Images/closed.gif"
    CollapseImageUrl="Images/open.gif"ID="TreeView1"
    Runat="server"DataSourceID="XmlDataSource1">
    <DataBindings>
    <asp:TreeNode BindingDataMember="Category"
    ValueField="ID"TextField="Name">
    </asp:TreeNodeBinding>
    <asp:TreeNode BindingDataMember="Description"
    ValueField="Value"
    TextField="Value">
    </asp:TreeNodeBinding>
    </DataBindings>
    </asp:TreeView>
    </div>
    <div>
    <asp:XmlDataSourceID="XmlDataSource1"Runat="server"
    DataFile="~/Data/Categories.xml">
    </asp:XmlDataSource>
    </div>
    </form>
    </body>
    </html>

    Here is just one example on codeproject, please refer it.

    Hope this will help you.

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 18, 2016 6:06 AM

All replies

  • User-830563764 posted
    The XML file will serve as a database for the XMLdatasource
    Of the data control. Apparent the <asp: code for the hyperlinks
    are not recognized as the links for opening the ASP.NET pages.
    Saturday, July 16, 2016 11:09 PM
  • User-2057865890 posted

    Hi wonjartran,

    You could use the NavigateUrl property to specify the URL to bind to the NavigateUrl property of a TreeNode object.

    Sample

    <div>
                <h3>TreeViewBinding Example</h3>
    
                <!-- Set the Text, ImageUrl, ImageToolTip, -->
                <!-- NavigateUrl, Value, and ToolTip       -->
                <!-- properties of a TreeNodeBinding       -->
                <!-- object declaratively.                 -->
                <asp:TreeView ID="BookTreeView"
                    DataSourceID="BookXmlDataSource"
                    Target="_blank"
                    runat="server">
    
                    <DataBindings>
                        <asp:TreeNodeBinding DataMember="Books"
                            Depth="0"
                            TextField="Text" />
                        <asp:TreeNodeBinding DataMember="Book"
                            Depth="1"
                            Text="Book Title"
                            ImageUrl="Image.jpg"
                            ImageToolTip="Book Image"
                            NavigateUrl="http://www.microsoft.com"
                            Value="BookID"
                            ToolTip="Book Information" />
                        <asp:TreeNodeBinding DataMember="Description"
                            Depth="2"
                            TextField="Text" />
                        <asp:TreeNodeBinding DataMember="Price"
                            Depth="2"
                            TextField="Value" />
                    </DataBindings>
    
                </asp:TreeView>
    
                <asp:XmlDataSource ID="BookXmlDataSource"
                    DataFile="Booklist.xml"
                    runat="server"></asp:XmlDataSource>
    
            </div>

     XML data

    <Books Text="Books List">
      <Book Text="Book Title One"
          Value="1"
          Image="Bookimage1.jpg"
          ImageToolTip="Book 1 Photo"
          Nav="http://www.microsoft.com"
          Tip="Book Title 1">
        <Description Text="Book Description">
        </Description>
        <Price Value="$1.99">
        </Price>
        <Author Text="Author Name"
            Value="LastName"
            Image="Authorimage1.jpg"
            Nav="http://www.microsoft.com"
            Tip="Author Name">
        </Author>
      </Book>
      <Book Text="Book Title Two"
          Value="2"
          Image="Bookimage2.jpg"
          ImageToolTip="Book 2 Photo"
          Nav="http://www.microsoft.com"
          Tip="Click Me">
        <Description Text="Book Description">
        </Description>
        <Price Value="$2.99">
        </Price>
        <Author Text="Author Name"
            Value="LastName"
            Image="Authorimage2.jpg"
            Nav="http://www.microsoft.com"
            Tip="Author Name">
        </Author>
      </Book>
    </Books>
    

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 18, 2016 5:53 AM
  • User603616845 posted

    Hi,

    How to code a XML file with the Hyperlinks

    I believe, you are just wondering for TreeView Menu which get the data from xml file and displayed as link.

    You can just follow these steps to create such type of menu.

    • Add an XmlDataSource control to the page and set its DataFile property to the name of the XML File
    • Then add a TreeView control and set its DataSourceID property to the ID of the XmlDataSource control.
    • Then map the nodes and their attributes in the XML file to the TreeView nodes by declaring the asp:TreeNodeBinding elements as part of the TreeView declaration

    XML File

    <?xmlversion='1.0'?>
    <!-- This file represents a fragment of a Categories inventory database -->
    <Categories>
    <CategoryID="1" Name="Beverages">
    <DescriptionValue="Soft drinks, coffees, teas, beers, and ales"/>
    </Category>
    <CategoryID="2" Name="Condiments">
    <DescriptionValue="Sweet and savory sauces, relishes, spreads, and
    seasonings"/>
    </Category>
    <CategoryID="3" Name="Confections">
    <DescriptionValue="Desserts, candies, and sweet breads"/>
    </Category>
    <CategoryID="4" Name="Dairy Products">
    <DescriptionValue="Cheeses"/>
    </Category>
    </Categories>

    and last you can bind this xml file data to xmldatasource of the treeview.

    <%@ PageLanguage="C#"%>
    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
     
    <htmlxmlns="http://www.w3.org/1999/xhtml">
    <headrunat="server">
    <title> Binding TreeView Control with an XML File</title>
    </head>
    <body>
    <formid="form1"runat="server">
    <div>
    <asp:TreeView ExpandImageUrl="Images/closed.gif"
    CollapseImageUrl="Images/open.gif"ID="TreeView1"
    Runat="server"DataSourceID="XmlDataSource1">
    <DataBindings>
    <asp:TreeNode BindingDataMember="Category"
    ValueField="ID"TextField="Name">
    </asp:TreeNodeBinding>
    <asp:TreeNode BindingDataMember="Description"
    ValueField="Value"
    TextField="Value">
    </asp:TreeNodeBinding>
    </DataBindings>
    </asp:TreeView>
    </div>
    <div>
    <asp:XmlDataSourceID="XmlDataSource1"Runat="server"
    DataFile="~/Data/Categories.xml">
    </asp:XmlDataSource>
    </div>
    </form>
    </body>
    </html>

    Here is just one example on codeproject, please refer it.

    Hope this will help you.

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 18, 2016 6:06 AM