|
Rank: Newbie Groups: Member
Joined: 8/1/2007 Posts: 5
|
I'm trying to specify the entire TreeView with an XML file, .net 1.1. I've stumbled upon an example that shows you can bind "Text" and "ItemID" to attributes in the XML file.
Where is the reference to which attributes I can put in or bind to in the XML file?
Other items I can't find in the help file: 1. How to programmatically (in ASP.NET C#) select a TreeNode from the control and set it as "Selected".
2. Expand the control to show this selected item and scroll it into view.
3. Turn off the animated drop down when you click and expand a node with sub nodes.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,182
|
Hi, Here is the documentation for binding to xml file: http://www.essentialobjects.com/ViewDoc.aspx?t=MenuCommon%2fDataBinding%2fpopulate_datasource.htmlScroll down and look for "Mapping data source attribute to item's property" section. By default, our TreeView recongizes a few attributes but you can use data binding object to manually map any attributes to most of the TreeNode properties. In order to set a node as selected, you would first need to find that node. Usually can be done by one of these two ways: 1. By index. For example, TreeView1.Nodes[0].ChildNodes[1], etc; 2. By ID/Path. You will need to use FindItem/SearchItem method on the TreeView class; Once you have the node, you can do: treeNode.Selected = true; treeNode.Expanded = true; To set it as expanded and selected. Note setting a node as expanded does NOT automatically expands its parent node. You can use the following code to scroll a treenode into view: treeNode.EnsureVisible(); As for your last question, I am not sure if you refer to the "slide" effect when a tree node expands or collapse. I do not think there is a way to turn that off in our current version. Hope this helps. Please feel free to let us know if you have any more questions. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/1/2007 Posts: 5
|
Yes, I did find this before, and it does not contain the information I need.
From your example code, I found out that "Text" is supported and "ItemID" is supported. The documentation you've specified above does not list these items.
So does it work this way: I can look on the TreeNode Properties documentation page, and take any property and use that as an attribute in the XML node?
About the FindItem, I use this and it returns a NULL. I set the ItemID to something like "23,99" and I searched for that. Is there a problem with what I've set the ItemID to?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,182
|
Hi,
No. You can not look on the TreeNode properties and take any of them to use in your XML node. Text is supported is because it's a shortcut of Text.Html. I am not sure how you come to conclusion that "ItemID" is supported though. It is not one of the automatically mapped item.
As for FindItem, you want to check these: 1. FindItem takes a path, not an ID. Please check whether you have only given it an ID; 2. Check whether you have correctly set your TreeNode's ItemID property;
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/1/2007 Posts: 5
|
Hmmm, I set ItemID in my XML file and when I get the event on the server side, then NavigationItemEventArgs.NavigationItem.ItemID is set properly to what I set it to in the XML file.
If you look in the sample code, go to the Default.aspx page, and bring up the Properties for the tvDemos control. Under Bindings for this control, find ItemID as the first binding.
I went ahead and added bindings to my code for Selected and Expanded to the XML file and it also picks these up and uses them to create the control.
It seems my problem with Find and Search is that I did it in the PageLoad() method, at which point the TreeView control has not loaded itself from the XML file, and thus Find and Search dutifully return NULLs.
So now, to complete my code, I'd like to get rid of the XML file on disk. Can I pass the XML file to the TreeView control, or can I parse the XML file and populate the TreeView control in the PageLoad() method?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,182
|
Hi Per,
Most properties are supported by DataBinding object. That's exactly what DataBinding object is for ---- for you to manually map a data field (or XML attribute) to a property. The document only lists the automatically mapped properties, for which you do not need a DataBinding object.
If you wish to do FindItem in Page_Load, you can call DataBind first, then call FindItem.
I am not sure what you mean by "get rid of the XML file on disk". We support many other data binding mechanism (most of which are based on ADO.NET that requires you to provide a DataTable or DataSet), but the only difference between XML file and those mechanism is where the data comes from. Once the code gets the data, all logics are the same from then on.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/1/2007 Posts: 5
|
Hi, Thanks for your help so far.
When I bind to an XML file, I have to save that file to disk, and then the TreeView control picks it up by reading from disk. I have the data in XML, so I want to pass the XML file as an XmlDocument object or as a string to the control.
I do not have access to the database, only to an XML file. If I cannot pass it the XML file, can I create nodes and add them to the control, one at a time? I suppose I will try something like TreeView.Nodes.Add (new TreeNode (...)).
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,182
|
Yes. TreeView.Nodes.Add(new TreeNode(...)) will work. You can give that a try. Another way is to use XmlDataSource. You can set the TreeView's DataSourceID to the ID of the data source control and then set the XmlDataSource's Data property to the XML string (instead of setting its DataFile property to the XML file). Note XmlDataSource is only available on ASP.NET 2.0.
|
|