This is a migrated thread and some comments may be shown as answers.

TreeView value property

3 Answers 79 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 19 Oct 2010, 11:48 AM
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

3 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 22 Oct 2010, 09:57 AM
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
0
Ajay
Top achievements
Rank 1
answered on 22 Oct 2010, 10:08 AM
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
0
Accepted
Nikolay Tsenkov
Telerik team
answered on 27 Oct 2010, 10:30 AM
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
Tags
TreeView
Asked by
Ajay
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Ajay
Top achievements
Rank 1
Share this question
or