TreeView value property

4 posts, 1 answers
  1. Ajay
    Ajay avatar
    42 posts
    Member since:
    Jul 2010

    Posted 19 Oct 2010 Link to this post

    Hi,

    I am facing issues while binding the XML data to a RADTreeview.

    If I use the declarative datasource and bind it to the TreeView it works, but when I specify the datasource from the codebehind, it is not able to set the Node.Value property.

    Below code is working:
    ASPX Code: 

    <telerik:RadTreeView ID="rtvCategories" runat="server" DataSourceID="XmlDataSourceCategories" SingleExpandPath="true" onnodeclick="rtvCategories_NodeClick" >
    <DataBindings>
    <telerik:RadTreeNodeBinding DataMember="Node" TextField="Text" ValueField="ID" Expanded="false" />
    </DataBindings>
    </telerik:RadTreeView>
    <asp:XmlDataSource runat="server" ID="XmlDataSourceCategories" DataFile="~/v1.xml" XPath="/Tree/Node" />

    XML
    <?xml version="1.0" encoding="utf-8" ?>
    <!--
    A Mapping xml file
      -->
    - <Tree>
    - <Node ID="3" Text="my category12">
      <Node ID="14" Text="disprine" />
      </Node>
    - <Node ID="3" Text="my category12">
      <Node ID="25" Text="Testitem" />
      </Node>
    - <Node ID="3" Text="my category12">
      <Node ID="25" Text="Testitem" />
      </Node>
    - <Node ID="3" Text="my category12">
      <Node ID="25" Text="Testitem" />
      </Node>
    - <Node ID="3" Text="my category12">
      <Node ID="35" Text="my Item" />
      </Node>
    - <Node ID="3" Text="my category12">
      <Node ID="35" Text="my Item" />
      </Node>
    - <Node ID="4" Text="Animal Category">
      <Node ID="25" Text="Testitem" />
      </Node>

      </Tree>


    Code not working (the data is getting displayed but Node Value always returns blank):
    <telerik:RadTreeView ID="rtvCategories" runat="server" SingleExpandPath="true" onnodeclick="rtvCategories_NodeClick" >
    <DataBindings>
    <telerik:RadTreeNodeBinding DataMember="Node" TextField="Text" ValueField="ID" Expanded="false" />
    </DataBindings>
    </telerik:RadTreeView>

    protected void Page_Load(object sender, EventArgs e)
    {
        string xmlData = "";

                // Below method 
    getXMLCategoryItemList
     returns the same xml as string
                xmlData = objFH.getXMLCategoryItemList().ToString();

                rtvCategories.LoadXmlString(xmlData);
                rtvCategories.DataBind();
    }


    protected void rtvCategories_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
    {
    lblResult.Text = e.Node.Value.ToString();
    }


    Kindly help me in resolving the issue.

    Thanks 
    Ajay Sharma
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 22 Oct 2010 Link to this post

    Hi Ajay,

    Well, LoadXmlString is not working with the binding mechanism. It has a separate implementation. The ID is mapped either to the ID property of the node, or it's in the Attributes collection (where all not-having-representation-in-the-property-bag of RadTreeNode properties go).

    As you stated the first solution will work for this scenario. What is the problem using the dataSource instead?
    If you are not able the use the first one, please, specify the reasons (you can share the requirements that you try and are not to implement this way) for that.

    Hope that soon we will resolve this!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Ajay
    Ajay avatar
    42 posts
    Member since:
    Jul 2010

    Posted 22 Oct 2010 Link to this post

    Hi Nikolay,

    Thanks for the attention.

    We can't use physical XML files because the data sent to our application (from business layer) is in XML format (same structure every time) with different data for each request made to the database.

    With the second approach (LoadXMLString) I am unable to fetch the Value property of nodes on click, Text property is working fine.

    Thanks & Regards
    Ajay Sharma
  4. Answer
    Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 27 Oct 2010 Link to this post

    Hello Ajay,

    You can use XmlDataSource with XML string, too.
    You just need to assign it to it's Data property. Here is a reference to it: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.data.aspx

    Hope this solves it!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top