This article was previously published under Q317878
The following Microsoft .NET Framework Class Library
namespace is referenced in this article:
System.Data
System.Data
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
<%@ Import Namespace="System.Data" %>
<html>
<script language="VB" runat="server">
Dim Cart As DataTable
Dim CartView As DataView
Function CreateDataSource() As ICollection
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
Dim i As Integer
For i = 0 To 3
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString() ' If you use "<Item>" instead of "Item",
' the row is not displayed correctly.
dr(2) = 1.23 *(i + 1)
dt.Rows.Add(dr)
Next i
dr = dt.NewRow()
dr(0) = 4
dr(1) = "<Item> " & 4.ToString() ' The problem occurs here.
' To resolve the problem, comment the preceding
' line, and uncomment the following line.
'dr(1) = "<Item> " & 4.ToString()
dr(2) = 1.23 *(4 + 1)
dt.Rows.Add(dr)
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
'Load this data only one time.
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
End Sub 'Page_Load
</script>
<body>
<form runat=server>
<h3><font face="Verdana">Q317878: DataGrid Web Server Control Does Not Display '<' and '>' Characters Correctly</font></h3>
<h4>Because you added the "<Item>" string in the DataGrid control, the data grid is not displayed correctly.</h4>
<h4>The first four rows in the data grid appear as expected. However, the last row demonstrates the problem. </h4>
<h5>This problem occurs because you include < and > around "Item". </h4>
<asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
ShowFooter="true"
AutoGenerateColumns="true">
<HeaderStyle BackColor="#00aaaa">
</HeaderStyle>
<FooterStyle BackColor="#00aaaa">
</FooterStyle>
</asp:DataGrid>
</form>
</body>
</html>
Keywords: KB317878, kbctrl, kbprb, kbwebforms, kbdatabinding, kbsystemdata