Wednesday, November 11, 2009

  1. Load xml file
  2. Read xml node
  3. Go through xml node using childnode method
  4. Load xml data to data table
  5. Bind datatable to gridview


Dim sourceDoc As New XmlDocument()
                sourceDoc.Load("http://e-conomic.excomhost.com/DesktopModules/dnnConnector/dnnconnectorOrders.aspx?portalid=0&OrderStatus=0_unpaid:1_paid:1_Betalt:1_betalt:0_ubetalt:0_Ej betald")
                Dim numList As XmlNodeList = sourceDoc.GetElementsByTagName("ORDER")

                Dim count As Integer = numList.Count

                If count > 0 Then
                    Dim nodeTable As New DataTable()
                    nodeTable.Columns.Add("Date", GetType(String))
                    nodeTable.Columns.Add("Name", GetType(String))
                    nodeTable.Columns.Add("Email", GetType(String))
                    nodeTable.Columns.Add("Total", GetType(String))
                    Label6.Text = count.ToString()

                    Dim TotPrice As Double = 0

                    For i As Integer = 0 To count - 1

                        Dim dr As DataRow = nodeTable.NewRow()
                        dr("Date") = numList(i).ChildNodes.Item(6).InnerText
                        dr("Name") = numList(i).ChildNodes.Item(12).ChildNodes.Item(18).ChildNodes.Item(0).InnerText + " " + numList(i).ChildNodes.Item(12).ChildNodes.Item(18).ChildNodes.Item(1).InnerText
                        dr("Email") = numList(i).ChildNodes.Item(12).ChildNodes.Item(18).ChildNodes.Item(2).InnerText

                        Dim b As XmlNode
                        Dim Tot As Double = 0
                        For Each b In numList(i).ChildNodes.Item(13)
                            Tot = Tot + Integer.Parse(b("QUANTITY").InnerText)
                            TotPrice = TotPrice + Double.Parse(b("PRICE").InnerText) * Integer.Parse(b("QUANTITY").InnerText)

                        Next
                        dr("Total") = Tot

                        nodeTable.Rows.Add(dr)
                    Next
                    TotPrice = Math.Round(TotPrice, 2)

                    Label7.Text = TotPrice.ToString()

                    Dim ds As New DataSet()
                    ds.Tables.Add(nodeTable)
                    GridView2.DataSource = ds
                    GridView2.DataBind()


                End If

No comments:

Post a Comment