Bind all XML files in the same format to a different DataGrid in a directory

Source: Internet
Author: User
Tags format bind count end integer
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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.