今天做了个导航条(使用外部文件XML)

今天做了个导航条(使用外部文件XML)这样

大大提高了应用程序的伸缩性
下面讲讲实现过程
先定义个XML文件(myxml.xml)

 1<items>
 2<item>
 3<name>文本一</name>
 4<link/>地址一   
 5</item>
 6<item>
 7<name>文本二</name>
 8<link/>地址二   
 9</item>
10<item>
11<name>文本三</name>
12<link/>地址三   
13</item>
14</items>

下面在后台代码中使用:
............
DataSet ds =new DataSet();
ds.ReadXml(Server.Mapth(myxml.xml));
foreach(DataRow item in ds.tables(0).rows)
{
DataRow row =new DataRow();
DataCell cell =new DataCell();
StringBuilder builder=new StringBuilder();
builder.Append("

1<a builder.append(""="" builder.append(item["link"]);="" herf='\"");'></a>

");
builder.Append(item["name"]);
builder.Appenf("

 1<a>");   
 2cell.text=builder.tostring();   
 3row.cells.add(cell);   
 4mytable.rows.add(row); //mytable 为自定义表名 
 5
 6} 
 7
 8如果要使用本段代码,还需要自己添加一些代 
 9
10码上面只是作为演示。</a>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus