4

I have an ASHX handler that returns an XML response (FileStructureXML.ashx).

Now I need to get the XML response from the ASHX handler and use it as a data source for my ASPX page.

If I point the XMLDataSource to a static XML file on the server, the treeview populates as expected. However, if I point the XMLDataSource to the ASHX handler instead of a static XML file on the server, it doesn't work.

Any help would be appreciated.

<body>
    <form id="form1" runat="server">
    <div>

        <asp:TreeView ID="TreeView_Folders" runat="server" DataSourceID="FileXML">
            <DataBindings>
                <asp:TreeNodeBinding DataMember="Directory" TextField="Name" />
                <asp:TreeNodeBinding DataMember="File" TextField="Name" />
            </DataBindings>        
        </asp:TreeView> 
    </div>
    <div>
        <asp:XmlDataSource ID="FileXML" runat="server" DataFile="FileStructureXML.ashx">
        </asp:XmlDataSource>
    </div>
    </form>
</body>

2 Answers2

2

I think that the XmlDataSource only works with an actual file, not a URL. You might be able to work around this by not specifying a DataFile property and loading the Data property dynamically in your code behind. I think the FirstChild.OuterXml selection is correct, but you may need to experiment. I'm not in a place where I can test it.

XmlDocument treeDoc = new XmlDocument();
treeDoc.Load( "~/FileStructureXML.ashx" ); // this takes a URL
FileXml.Data = treeDoc.FirstChild.OuterXml; // everything after the xml definition
tvanfosson
  • 524,688
  • 99
  • 697
  • 795
0
Dim oDataSet As New DataSet
    Public Sub PopulateTree(ByVal ParentId As String, ByVal TVNode As TreeNode)
        Dim oDataView As New DataView(oDataSet.Tables(0), "ParentID='" & ParentId & "'", 
        "DATA", DataViewRowState.OriginalRows)
        Dim oDataRow As DataRowView
        For Each oDataRow In oDataView
            Dim oTreeNode As New TreeNode(oDataRow("DATA"))
            Dim oComboBox As New ComboBox
            If TVNode Is Nothing Then
            Else
                TVNode.Nodes.Add(oTreeNode)
                PopulateTree(oDataRow("ID"), oTreeNode)
            End If
        Next
    End Sub

This is how U call the above function 
PopulateTree(0, tvPost.TopNode)
tvPost - its the name of TreeView T

To Read More Click this link
http://muruganad.com/ASP.NET/ASP_.NET_How_to_Populate_a_TreeView_Control_With_TreeNode_s_Using_recursive_algorithm_or_recursion_.html