惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
MyScale Blog
MyScale Blog
G
GRAHAM CLULEY
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Y
Y Combinator Blog
The Register - Security
The Register - Security
宝玉的分享
宝玉的分享
S
Schneier on Security
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
G
Google Developers Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
S
Security @ Cisco Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
M
MIT News - Artificial intelligence
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
W
WeLiveSecurity
Latest news
Latest news
博客园 - 【当耐特】
P
Palo Alto Networks Blog
博客园 - 叶小钗
Simon Willison's Weblog
Simon Willison's Weblog
Jina AI
Jina AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Troy Hunt's Blog
L
LangChain Blog
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
C
Check Point Blog
O
OpenAI News
C
Cisco Blogs
T
Tor Project blog
A
About on SuperTechFans
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
Attack and Defense Labs
Attack and Defense Labs

博客园 - 努力前上

button按回车触发后台 - 努力前上 - 博客园 Connectionstrings - 努力前上 - 博客园 [C#]包含DataSet类的XML架构怎么不自动生成CS文件了(XSD和CS文件不能合并) Asp.Net 备份和恢复SQL SERVER 数据库 提取HTML代码中文字的C#函数 (转) - 努力前上 - 博客园 危险字符过滤的类(最新完善版)(1) Tree使用 常用的一些javascript小技巧(转) 利用TreeView控件动态生成无限级树(转) - 努力前上 - 博客园 Microsfot.Web.UI.WebControls.TreeView JavaScript控制方法研究(转) (二)execCommand()函数可用参数大解析 JavaScript--execCommand指令集 JS 无刷新排序 js 技巧杂引(转) HTML代码过滤函数 DataGrid 颜色交替 DataGrid双击事件 javascript调用webservice [垃圾猪]防盗链IHttpHandler源码
利用TreeView控件动态生成无限级树(续:通过绑定动态xml文件)(转) - 努力前上 - 博客园
努力前上 · 2006-01-07 · via 博客园 - 努力前上

在上一篇
利用TreeView控件动态生成无限级树
中提到的那个动态生成XML文件进行绑定的办法
今天也被我实现了

把生成XML文件的代码单独放到一个页面中,比如说叫GetXml.aspx页中去
然后指定

TreeView2.TreeNodeSrc = "GetXml.aspx";

而这个GetXml.aspx.cs中的代码如下

private void SendXml()
        
{
            
//Create Xml File
            XmlDocument objXmlDoc = new XmlDocument();

            
//Insert Xml Declaration
            XmlDeclaration objXmlDeclare = objXmlDoc.CreateXmlDeclaration("1.0""UTF-8""yes");
            objXmlDoc.InsertBefore(objXmlDeclare, objXmlDoc.DocumentElement);

            XmlElement objRootElem 
= objXmlDoc.CreateElement("TREENODES");
            objXmlDoc.AppendChild(objRootElem);

            CreateXml(objXmlDoc, objRootElem, 
0);

            System.Xml.XmlTextWriter xmlwriter 
= new System.Xml.XmlTextWriter(Response.OutputStream,Response.ContentEncoding);
            xmlwriter.Formatting 
= Formatting.Indented;
            xmlwriter.Indentation 
= 4;
            xmlwriter.IndentChar 
= ' ';
            objXmlDoc.WriteTo(xmlwriter);
            xmlwriter.Flush();
            Response.End();
            xmlwriter.Close();
        }


        
private void CreateXml(XmlDocument objXMLDoc, XmlElement objRootElem, int belong)
        
{
            
//Get DataSet
            DataSet ds = new DataSet();
            
foreach(DataRow dr in ds.Tables[0].Rows)
            
{
                
//Create ChildNode TreeNode
                XmlElement objXmlElem = objXMLDoc.CreateElement("TREENODE");
                objRootElem.AppendChild(objXmlElem);

                
//Create Attributes Text
                XmlAttribute objXmlAttText = objXMLDoc.CreateAttribute("Text");
                objXmlAttText.Value 
= dr["text"].ToString().Trim();
                objXmlElem.SetAttributeNode(objXmlAttText);

                
//Create Attributes CheckBox
                XmlAttribute objXmlAttCB = objXMLDoc.CreateAttribute("CheckBox");
                objXmlAttCB.Value 
= "True";
                objXmlElem.SetAttributeNode(objXmlAttCB);

                
//Create Attributes Expanded
                XmlAttribute objXmlAttExp = objXMLDoc.CreateAttribute("Expanded");
                objXmlAttExp.Value 
= "True";
                objXmlElem.SetAttributeNode(objXmlAttExp);

                
int id = int.Parse(dr["id"].ToString().Trim());
                CreateXml(objXMLDoc, objXmlElem, id);
            }

        }

函数的递归思想用的仍然是上一篇中的同样的思想
这里把生成的objXMLdoc文件用XmlTextWriter写入到一个Xml流中
然后利用xmlwriter.Flush()的方式进行输出
这样就可以得到这个Xml文件了
在PageLoad函数里调用这个SendXml()方法即可