如何将TreeView序列化加载到GridView中

时间:2009-11-11 12:42:26

标签: asp.net vb.net gridview treeview xml-serialization

从TreeView中,我得到了这个XML序列化:

<?xml version="1.0" encoding="utf-16"?><node text="&lt;span id='c6f5ab9e-d08f-448a-9143-02d174317c07' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Zürich&lt;/span&gt;" value="c6f5ab9e-d08f-448a-9143-02d174317c07" navigateurl="" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False">  <node text="&lt;span id='f28df8d9-f83f-494c-a88e-591c7266c455' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Gebäude 1&lt;/span&gt;" value="f28df8d9-f83f-494c-a88e-591c7266c455" navigateurl="" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False">    <node text="&lt;span id='e8cd5ca3-e25c-4900-b49e-53a5a6b0f19a' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Etage 1&lt;/span&gt;" value="e8cd5ca3-e25c-4900-b49e-53a5a6b0f19a" navigateurl="" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False">      <node text="&lt;span id='31360723-0be2-47e5-814c-4837c174c9a1' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Raum 203&lt;/span&gt;" value="31360723-0be2-47e5-814c-4837c174c9a1" navigateurl="javascript:SetUrl('./raumplaner.aspx?raum=31360723-0be2-47e5-814c-4837c174c9a1');" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False" />      <node text="&lt;span id='5accd32f-7a85-46de-99a3-0853843b4e99' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Raum 211&lt;/span&gt;" value="5accd32f-7a85-46de-99a3-0853843b4e99" navigateurl="javascript:SetUrl('./raumplaner.aspx?raum=5accd32f-7a85-46de-99a3-0853843b4e99');" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False" />      <node text="&lt;span id='67774365-233b-4176-93f4-65c4e4953daa' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Raum 511&lt;/span&gt;" value="67774365-233b-4176-93f4-65c4e4953daa" navigateurl="javascript:SetUrl('./raumplaner.aspx?raum=67774365-233b-4176-93f4-65c4e4953daa');" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False" />      <node text="&lt;span id='ea86389f-b6ef-433e-97da-e3395f216ee5' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Raum 4&lt;/span&gt;" value="ea86389f-b6ef-433e-97da-e3395f216ee5" navigateurl="javascript:SetUrl('./raumplaner.aspx?raum=ea86389f-b6ef-433e-97da-e3395f216ee5');" populateondemand="False" showcheckbox="false" checked="False" expanded="True" selected="False" />    </node>  </node></node>

现在我想将所有节点读入gridview 所以我使用XMLdatasource,将其指向XML文件,并将数据绑定到gridview。

问题是,因为它是包含文件夹和子文件夹的导航结构,只包含项目,所以它只加载第一个文件夹,而不是其他内容。

gridview:`                      

            <asp:GridView ID="GridView1" DataSourceID="xmldsDefaultMenu" runat="server" AutoGenerateColumns="false">
     <Columns>
            <asp:BoundField ReadOnly="True" 
              HeaderText="Name" 
              InsertVisible="False" 
              DataField="text" 
              SortExpression="ProductID">
            </asp:BoundField>

            <asp:BoundField HeaderText="ID" 
              DataField="value" 
              SortExpression="ProductName">
            </asp:BoundField>

            <asp:BoundField HeaderText="URL" 
                DataField="navigateurl" 
                SortExpression="QuantityPerUnit">
            </asp:BoundField>
        </Columns>        
    </asp:GridView>
`

树视图:

            <asp:TreeView ID="TreeView1" Runat="server" DataSourceID="XmlDataSource1" ImageSet="Arrows" >
                <HoverNodeStyle    BackColor="#D7E8F3" BorderColor="#A7B4CE" Font-Underline="false" />
                <SelectedNodeStyle ForeColor="#FF0000" BackColor="#FAF3F4" BorderColor="#A7B4CE" Font-Underline="False" HorizontalPadding="0px" VerticalPadding="0px" />

                <DataBindings>
                     <asp:TreeNodeBinding DataMember="node" TextField="text" ValueField="value" PopulateOnDemand="false" NavigateUrlField="navigateurl" >
                    </asp:TreeNodeBinding>
                </DataBindings>
            </asp:TreeView>   

1 个答案:

答案 0 :(得分:1)

哦,解决了:

        Dim oDataSet As System.Data.DataSet = New System.Data.DataSet
    oDataSet.ReadXml("C:\inetpub\wwwroot\rmplnr\SavedMenu\Start.xml")
    Me.GridView1.DataSource = oDataSet
    Me.GridView1.DataBind()