<!--某一目录下的所有 XML文件绑定到不同的DataGrid的方法。
原著:孟子E章
修改:塞北的雪
-->
<%@ Page Language="vb"%>
<%@ Import NameSpace = "System" %>
<%@ Import NameSpace = "System.Xml" %>
<%@ Import NameSpace = "System.IO" %>
<%@ Import NameSpace = "System.Collections" %>
<%@ Import NameSpace = "System.Web" %>
<%@ Import NameSpace = "System.Web.UI" %>
<%@ Import NameSpace = "System.Web.UI.WebControls" %>
<%@ Import NameSpace = "System.Data" %>
<%@ Import NameSpace = "System.Drawing" %>
<SCRIPT runat="Server">
Sub Page_Load( sender as object, e as System.EventArgs)
Dim dir As DirectoryInfo = New DirectoryInfo(Server.MapPath("remark\"))
Dim files As FileInfo() = dir.GetFiles()
Dim count As Integer = files.Length
Dim i As Integer
dim j as Integer
dim k as Integer
For i = 0 To count - 1
If files(i).Name.SubString(files(i).Name.LastIndexOf(".")) = ".xml" Then
Dim ds As New DataSet()
ds.ReadXml(files(i).FullName)
for k=0 to ds.tables.count-1
Dim dt as DataGrid = New DataGrid()
dt.ID = "DataGrid" + i.ToString() + k.ToString()
dt.HeaderStyle.BackColor=Color.Red
dt.AutoGenerateColumns=false
Dim MyName as BoundColumn()
redim MyName(ds.tables(k).columns.count)
for j=0 to ds.tables(k).columns.count-1
MyName(j)=new BoundColumn()
MyName(j).HeaderText=ds.tables(k).columns(j).columnname
MyName(j).DataField=ds.tables(k).columns(j).columnname
dt.Columns.AddAt(0, MyName(j))
next
dt.DataSource = ds.Tables(k)
dt.DataBind()
Me.Controls.Add(dt)
next
End If
Next
End Sub
</SCRIPT>
本文地址:http://com.8s8s.com/it/it8655.htm