将某一目录下的所有相同格式的 XML文件绑定到不同的DataGrid

介绍了将某一目录下相同格式的XML文件绑定到不同DataGrid的方法,涉及信息技术中数据处理与展示相关内容。

将某一目录下的所有相同格式的 XML文件绑定到不同的DataGrid的方法。










<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="名字"
      MyName.DataField="Name"

      MyProductID.HeaderText="序号"
      MyProductID.DataField="ProductID"

      Price.HeaderText="价格"
      Price.DataField="Price"

      Quantity.HeaderText="数量"
      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>


版权声明:本站所有程序只供学习参考,不得复制和转载。如本文牵涉版权问题,本人不承担相关责任,请版权拥有者直接与文章作者联系解决。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值