<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All" ShowLines="true" ShowExpandCollapse="true">
<Nodes>
<asp:TreeNode Value="Child1" Expanded="True" Text="Server1">
<asp:TreeNode Value="Grandchild1" Text="MBS1" />
<asp:TreeNode Value="Grandchild2" Text="MBS2" />
</asp:TreeNode>
<asp:TreeNode Value="Child2" Text="Server2" />
<asp:TreeNode Value="Child3" Expanded="True" Text="MBS3">
<asp:TreeNode Value="Grandchild1" Text="MBS4" />
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
<p>
<asp:Button ID="btnCreateXML" runat="server" onclick="btnCreateXML_Click"
Text="Create XML" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
</form>
代码背后:
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.Attributes.Add("onclick", "javascript: OnTreeClick();");
}
protected void btnCreateXML_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode Parent = doc.CreateElement("Parent");
XmlNode Child = doc.CreateElement("Child");
doc.Save(path);
string temp;
char[] al = new char[5];
foreach (TreeNode node in TreeView1.CheckedNodes)
{
//temp = (node.Text).ToString();
Child.InnerText = node.Text;
Parent.AppendChild(Child);
Response.Write(node.Text);
// al[node] += al[node];
}
}
}
我确实有 asp.net TreeView 控件,当我检查节点时,我可以从 btnCreateXML 的单击事件后面的代码中获取这些检查值。我将进入 node.Text 的值,我想为它创建 XML 文件。如何实现这一点(仅适用于选定的节点)?任何帮助都会很棒!