K
Kevin
Hi,
I'm attempting to load raw XML(XML string), parse it and populate a
text box, parse it further into an ArrayList, then set the ArrayList
as the DataSource of a DataGrid.
I had no problem getting this to work in a VB.NET Windows App. But I
can't seem to populate the DataGrid in an VB.NET Web App.
When I run the Windows App, textbox is loaded and datagrid is
populated.
When I run the Web App, textbox is loaded, but I can't seem to figure
out why the datagrid doesn't populate.
Any help would be appreciated. This is my first .NET programming
attempt. Any suggestions on overall programming technique is also
appreciated.
Thanks, Kev.
Here are my two aspx and aspx.vb pages with their respetive code.
**************
WebForm1.aspx:
**************
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 24px;
POSITION: absolute; TOP: 24px" runat="server"
Width="272px" Height="32px" Enabled="true"></asp:TextBox>
<aspataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px;
POSITION: absolute; TOP: 64px" runat="server"
Height="208px" Width="312px"></aspataGrid>
</form>
</body>
</HTML>
*****************
WebForm1.aspx.vb:
*****************
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim MyXMLDocument As System.Xml.XmlDocument
Dim MyXpath As String
Dim MyNodeList As System.Xml.XmlNodeList
Dim MyNode As System.Xml.XmlNode
Dim x As Integer
Dim y As Integer
Dim myAL As New ArrayList
Dim myTest As New clsTest
DataGrid1.DataSource = Nothing
MyXMLDocument = New System.Xml.XmlDocument
MyXMLDocument.LoadXml("<list user-id='10.100.100.112'
list-id='15357' list-description='Import from GIS'
query-id='tnfhkxzhunwrhoah4nt5pc45-LIST' list-type='UWI'
list-status='start' list-title='' list-datasource='3'
value-1-type='varchar2' value-2-type='not-used'
value-3-type='not-used' list-count='4'><list-element
value-1='100072204721W400' value-2='' value-3=''/><list-element
value-1='1W0131504721W400' value-2='' value-3=''/><list-element
value-1='100151604721W400' value-2='' value-3=''/><list-element
value-1='100091604721W400' value-2='' value-3=''/></list>")
MyXpath = "/list/@list-type"
MyNodeList = MyXMLDocument.SelectNodes(MyXpath)
MyNode = MyXMLDocument.SelectSingleNode(MyXpath)
'Display in textbox
TextBox1.Text = MyNode.InnerXml
MyXpath = "/list/list-element"
MyNodeList = MyXMLDocument.SelectNodes(MyXpath)
For x = 0 To MyNodeList.Count - 1
myTest = New clsTest
myTest.A = MyNodeList.Item(x).Attributes(0).InnerXml
myTest.B = MyNodeList.Item(x).Attributes(1).InnerXml
myTest.C = MyNodeList.Item(x).Attributes(2).InnerXml
myAL.Add(myTest)
Next
'Set Datasource for DataGrid
DataGrid1.DataSource = myAL
End Sub
End Class
Public Class clsTest
Private m_strA As String
Private m_strB As String
Private m_strC As String
Public Property A()
Get
Return m_strA
End Get
Set(ByVal Value)
m_strA = Value
End Set
End Property
Public Property B()
Get
Return m_strB
End Get
Set(ByVal Value)
m_strB = Value
End Set
End Property
Public Property C()
Get
Return m_strC
End Get
Set(ByVal Value)
m_strC = Value
End Set
End Property
End Class
I'm attempting to load raw XML(XML string), parse it and populate a
text box, parse it further into an ArrayList, then set the ArrayList
as the DataSource of a DataGrid.
I had no problem getting this to work in a VB.NET Windows App. But I
can't seem to populate the DataGrid in an VB.NET Web App.
When I run the Windows App, textbox is loaded and datagrid is
populated.
When I run the Web App, textbox is loaded, but I can't seem to figure
out why the datagrid doesn't populate.
Any help would be appreciated. This is my first .NET programming
attempt. Any suggestions on overall programming technique is also
appreciated.
Thanks, Kev.
Here are my two aspx and aspx.vb pages with their respetive code.
**************
WebForm1.aspx:
**************
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 24px;
POSITION: absolute; TOP: 24px" runat="server"
Width="272px" Height="32px" Enabled="true"></asp:TextBox>
<aspataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px;
POSITION: absolute; TOP: 64px" runat="server"
Height="208px" Width="312px"></aspataGrid>
</form>
</body>
</HTML>
*****************
WebForm1.aspx.vb:
*****************
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim MyXMLDocument As System.Xml.XmlDocument
Dim MyXpath As String
Dim MyNodeList As System.Xml.XmlNodeList
Dim MyNode As System.Xml.XmlNode
Dim x As Integer
Dim y As Integer
Dim myAL As New ArrayList
Dim myTest As New clsTest
DataGrid1.DataSource = Nothing
MyXMLDocument = New System.Xml.XmlDocument
MyXMLDocument.LoadXml("<list user-id='10.100.100.112'
list-id='15357' list-description='Import from GIS'
query-id='tnfhkxzhunwrhoah4nt5pc45-LIST' list-type='UWI'
list-status='start' list-title='' list-datasource='3'
value-1-type='varchar2' value-2-type='not-used'
value-3-type='not-used' list-count='4'><list-element
value-1='100072204721W400' value-2='' value-3=''/><list-element
value-1='1W0131504721W400' value-2='' value-3=''/><list-element
value-1='100151604721W400' value-2='' value-3=''/><list-element
value-1='100091604721W400' value-2='' value-3=''/></list>")
MyXpath = "/list/@list-type"
MyNodeList = MyXMLDocument.SelectNodes(MyXpath)
MyNode = MyXMLDocument.SelectSingleNode(MyXpath)
'Display in textbox
TextBox1.Text = MyNode.InnerXml
MyXpath = "/list/list-element"
MyNodeList = MyXMLDocument.SelectNodes(MyXpath)
For x = 0 To MyNodeList.Count - 1
myTest = New clsTest
myTest.A = MyNodeList.Item(x).Attributes(0).InnerXml
myTest.B = MyNodeList.Item(x).Attributes(1).InnerXml
myTest.C = MyNodeList.Item(x).Attributes(2).InnerXml
myAL.Add(myTest)
Next
'Set Datasource for DataGrid
DataGrid1.DataSource = myAL
End Sub
End Class
Public Class clsTest
Private m_strA As String
Private m_strB As String
Private m_strC As String
Public Property A()
Get
Return m_strA
End Get
Set(ByVal Value)
m_strA = Value
End Set
End Property
Public Property B()
Get
Return m_strB
End Get
Set(ByVal Value)
m_strB = Value
End Set
End Property
Public Property C()
Get
Return m_strC
End Get
Set(ByVal Value)
m_strC = Value
End Set
End Property
End Class