<
SiteMap
>
< item Text ="标题一" Id ="1" />
< item Text ="标题二" Id ="4" />
< item Text ="标题三" Id ="5" />
< item Text ="标题四" Id ="6" />
< item Text ="标题五" Id ="7" />
</ SiteMap >
C#代码:
< item Text ="标题一" Id ="1" />
< item Text ="标题二" Id ="4" />
< item Text ="标题三" Id ="5" />
< item Text ="标题四" Id ="6" />
< item Text ="标题五" Id ="7" />
</ SiteMap >
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 }
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 }