Datagrid|xml
The method of binding all XML files in the same format in a directory to a different DataGrid.
<%@ 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"%>
<script runat=server>
Sub Page_Load (sender as object, e as System.EventArgs)
Dim dir as DirectoryInfo = New DirectoryInfo ("D:\Web")
Dim files as FileInfo () = dir. GetFiles ()
Dim count as Integer = files. Length
Dim i 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 ("D:\Web\c.xml")
ds. READXML (Files (i). FullName)
Dim dt as DataGrid = New DataGrid ()
dt. ID = "DataGrid" + i.tostring ()
dt. Autogeneratecolumns=false
Dim myname as BoundColumn = New BoundColumn ()
Dim Myproductid as BoundColumn = New BoundColumn ()
Dim Price as BoundColumn = New BoundColumn ()
Dim Quantity as BoundColumn = New BoundColumn ()
myname.headertext= "name."
Myname.datafield= "Name"
myproductid.headertext= "Serial Number"
Myproductid.datafield= "ProductID"
price.headertext= "Price"
Price.datafield= "Price"
quantity.headertext= "Quantity"
Quantity.datafield= "Quantity"
Dt. Columns.addat (0, MyName)
Dt. Columns.addat (0, Myproductid)
Dt. Columns.addat (2, price)
Dt. Columns.addat (3, Quantity)
Dt. DataSource = ds. Tables ("Product")
Dt. DataBind ()
ME.CONTROLS.ADD (DT)
End If
Next
End Sub
</script>
<form runat=server>
</form>