Microsoft KB Archive/317878

From BetaArchive Wiki

Article ID: 317878

Article Last Modified on 6/5/2003



APPLIES TO

  • Microsoft .NET Framework 1.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer (Programming) 6.0



This article was previously published under Q317878

The following Microsoft .NET Framework Class Library namespace is referenced in this article:

System.Data

SYMPTOMS

When you create a Web application that displays data in a DataGrid control, if the data contains the less than character (<) and the greater than character (>), Microsoft Internet Explorer interprets these characters as Hypertext Markup Language (HTML) directives. As a result, the string of data between the "<" and ">" characters in the DataGrid control cannot be displayed.

RESOLUTION

To resolve this problem, change "<" to "<" and ">" to ">".

STATUS

This bug was corrected in Microsoft .NET Framework 1.0 and in Microsoft Internet Explorer (Programming) 5.01, 5.5, and 6.0.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new file named Repro.aspx, and then add the following code to this file:

    <%@ 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>
                        
  2. Open the Repro.aspx file in Internet Explorer. Note that Internet Explorer does not display the fourth row, which contains the "<Item>" string, correctly.



Additional query words: angle brackets

Keywords: kbwebforms kbsystemdata kbdatabinding kbctrl kbprb KB317878