一聚教程网:一个值得你收藏的教程网站

热门教程

某一目录下的所有 XML文件绑定到不同的DataGrid的方法

时间:2022-06-30 09:31:36 编辑:袖梨 来源:一聚教程网


<%@ 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" %>
T 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


热门栏目