I got a page that loads a xml file into a treeview control. I want it to
sort the data before sending it to the treeview control is that possible?
<root>
<level1 name="" src="" order="0">
<level1.2 .. order="5">
<level1.2 .. order="3">
<level1.2 .. order="2">
<level1 .. order="2">
<level1 .. order="1">
I want first level1 nodes to be sorted accorded to the order column. Then i
want all sub levels to be sorted, sor 1.2 should be sorted with only 1.2 and
1.3 should be sorte with only 1.3.
Like a window folder, in one folder you can sort the items in any order you
want, then when you move to the next folder you can sort that one.
Is it possible or do you have to rewrite the xml file, change the position
of line 3 and 4 with read/write, in order to change how they are viewed
This is the code witch i load the treeview control:
(this code also adds a node beneath every node with the text "Ny sida
....(new page)")
protected void Page_Load(object sender, EventArgs e)
{
TreeNode mNode;
TreeNode mNode2;
XmlDocument mdoc = new XmlDocument();
mdoc.Load("struct.xml");
page_treeview.Nodes.Clear();
mNode = new TreeNode(mdoc.DocumentElement.Name, "",
Image_Path_To_Rootimage);
page_treeview.Nodes.Add(mNode);
TreeNode tNode = new TreeNode();
tNode = page_treeview.Nodes[0];
AddNode(mdoc.DocumentElement, tNode);
mNode2 = new TreeNode("Ny sida...", "n0");
page_treeview.Nodes.AddAt(1, mNode2);
page_treeview.ExpandAll();
page_treeview.CollapseAll();
}
private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;
TreeNode nNode;
int i;
// Loop through the XML nodes until the leaf is reached.
// Add the nodes to the TreeView during the looping process.
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for (i = 0; i <= nodeList.Count - 1; i++)
{
xNode = inXmlNode.ChildNodes[i];
inTreeNode.ChildNodes.Add(new
TreeNode(xNode.Attributes["name"].Value, xNode.Attributes["id"].Value,
Image_Path_To_Pageimages));
nNode = new TreeNode();
nNode.Text = "Ny sida...";
nNode.Value = "n" + xNode.Attributes["id"].Value;
inTreeNode.ChildNodes.Add(nNode);
tNode = inTreeNode.ChildNodes[i*2];
AddNode(xNode, tNode);
}
}
else
{
// Here you need to pull the data from the XmlNode based on the
// type of node, whether attribute values are required, and so
forth.
inTreeNode.Text = inXmlNode.Attributes["name"].Value;
inTreeNode.Value = inXmlNode.Attributes["id"].Value;
inTreeNode.ImageUrl = Image_Path_To_Pageimages;
nNode = new TreeNode();
nNode.Text = "Ny sida...";
nNode.Value = "n" + inXmlNode.Attributes["id"].Value;
inTreeNode.ChildNodes.Add(nNode);
}
}
Patrick