posts - 930,  comments - 588,  views - 402万
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
        ComponentArt.Web.UI控件绑定所用XML,同时用于DropDownList的绑定,XML如下:
<SiteMap>
  
<item Text="标题一" Id="1" />
  
<item Text="标题二"Id="4" />
  
<item Text="标题三"Id="5"/>
  
<item Text="标题四" Id="6"/>
  
<item Text="标题五" Id="7" />
</SiteMap>
         C#代码:
 1         /// <summary>
 2         /// 从XML文件读取数据绑定到列表控件
 3         /// </summary>
 4         /// <example>
 5         /// <code>
 6         /// ReadXMLBindListControl("tabData.xml", this.Ddl1);
 7         /// </code>
 8         /// </example>
 9         /// <param name="filepath">XML文件路径</param>
10         /// <param name="lic">ListControl ID</param>
11         public static void ReadXMLBindListControl(string filepath, System.Web.UI.WebControls.ListControl lic)
12         {
13             string path = System.Web.HttpContext.Current.Server.MapPath(filepath);
14             if (!File.Exists(path))
15             {
16                 throw new FileNotFoundException("Specified XmlFile (" + filepath + ") does not exist.");
17             }
18 
19             lic.Items.Clear();
20             XmlDocument doc = new XmlDocument();
21             doc.Load(path);
22             foreach (XmlNode node in doc.DocumentElement.ChildNodes)
23             {
24                 if (node.NodeType == XmlNodeType.Element)
25                 {
26                     lic.Items.Add(new ListItem(node.Attributes[0].Value, node.Attributes[1].Value));
27                 }
28             }
29         }
posted on   PetterLiu  阅读(562)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示