googenfrog
03-29-2009, 11:29 AM
Hello all...
In the following code I have a button that will display customer orders read from an xml file. Currently the button click renders all the orders. What I want is when the user selects a customer from a dropdownlist it would render their specific xml order but I want to use the class objects. I'm not sure how to do this. Also I want to read the connection string from the web config file but not sure how to do this either. I have put the connection string in the web config but don't know how to access it from the page. I am trying to just use databinding and not the SqlDataSource property. Thanks
Imports System.Data
Imports System.IO
Imports System.Xml
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs)
Panel1.Visible = True
Dim path As String = ""
Label1.Text = ""
Dim ds As New Data.DataSet()
ds.ReadXml(Server.MapPath("~/App_Data/orders.xml"))
' loop through each DataTable and output contents
For Each table As DataTable In ds.Tables
' dynamically output the name of table
Dim caption As New Literal()
caption.Text = "<h2>Customer Orders </h2>"
PlaceHolder1.Controls.Add(caption)
' dynamically create a grid view
Dim grid As New GridView()
' set up its look and data bind it to the DataTable
grid.CellPadding = 3
grid.DataSource = table.DefaultView
grid.DataBind()
' add this GridView to PlaceHolder
PlaceHolder1.Controls.Add(grid)
Next
End Sub
Public Class Customers
Private m_id As Integer
Public Property ID() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
Private m_name As String
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal value As String)
m_name = value
End Set
End Property
Public Class Orders
Private m_id As Integer
Public Property ID() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
Private m_custId As Integer
Public Property CustomerID() As Integer
Get
Return m_custId
End Get
Set(ByVal value As Integer)
m_custId = value
End Set
End Property
Private m_amount As Double
Public Property Amount() As Double
Get
Return m_amount
End Get
Set(ByVal value As Double)
m_amount = value
End Set
End Property[CODE]
End Class
End Class
End Class[\CODE]
In the following code I have a button that will display customer orders read from an xml file. Currently the button click renders all the orders. What I want is when the user selects a customer from a dropdownlist it would render their specific xml order but I want to use the class objects. I'm not sure how to do this. Also I want to read the connection string from the web config file but not sure how to do this either. I have put the connection string in the web config but don't know how to access it from the page. I am trying to just use databinding and not the SqlDataSource property. Thanks
Imports System.Data
Imports System.IO
Imports System.Xml
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs)
Panel1.Visible = True
Dim path As String = ""
Label1.Text = ""
Dim ds As New Data.DataSet()
ds.ReadXml(Server.MapPath("~/App_Data/orders.xml"))
' loop through each DataTable and output contents
For Each table As DataTable In ds.Tables
' dynamically output the name of table
Dim caption As New Literal()
caption.Text = "<h2>Customer Orders </h2>"
PlaceHolder1.Controls.Add(caption)
' dynamically create a grid view
Dim grid As New GridView()
' set up its look and data bind it to the DataTable
grid.CellPadding = 3
grid.DataSource = table.DefaultView
grid.DataBind()
' add this GridView to PlaceHolder
PlaceHolder1.Controls.Add(grid)
Next
End Sub
Public Class Customers
Private m_id As Integer
Public Property ID() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
Private m_name As String
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal value As String)
m_name = value
End Set
End Property
Public Class Orders
Private m_id As Integer
Public Property ID() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
Private m_custId As Integer
Public Property CustomerID() As Integer
Get
Return m_custId
End Get
Set(ByVal value As Integer)
m_custId = value
End Set
End Property
Private m_amount As Double
Public Property Amount() As Double
Get
Return m_amount
End Get
Set(ByVal value As Double)
m_amount = value
End Set
End Property[CODE]
End Class
End Class
End Class[\CODE]