BUG: Grid DTC Interprets HTML Tag as HTML

ID: Q192033


The information in this article applies to:
  • Microsoft Visual Studio 6.0


SYMPTOMS

The Grid DTC interprets a table containing an HTML tag such as <HR> as HTMLrather than text. In this case a horizontal rule would be displayed in thecells of the DTC Grid rather than the text "<HR>."


CAUSE

All data from a database is put into the DTC Grid as raw text. The browser simply processes this text as though it were any other HTML text.


RESOLUTION

The best solution is to format the data in the database in the way you want it to appear. If you choose not to format the data in your database so that it appears as HTML source code (see item 3), it will need to be converted (see items 1 and 2).

Converting Your Data Before It Is Put Into the DTC Grid

  1. Go to the Custom property pages for the DTC Grid.


  2. On the Data tab in the Edit columns area, you will see a text box labeled "Field/expression:". If you prefix the data in this field with an "=", it is interpreted as javascript. If you put the name of a field within "[]" (square brackets) the grid will display the data for that field from the recordset in the DTC Grid.


Converting Data During Rendering of Grid

  1. For ASP (server side), use the following expression:


  2. =Server.HTMLEncode([fieldname])
  3. For DHTML (client side), it is necessary to write a function to convert the string to display properly:


  4. example: =MyHTMLEncode([field1])
    (See the example in MORE INFORMATION section).

  5. Format the data in the database so it will display properly (&lt;HR&gt; rather than <HR>).



STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

A sample HTMLEscape() function:


   // This function is time-consuming and it would be best to avoid
   // using it unless it is absolutely necessary.

   function myHTMLEncode(stData)
   {
      // A temporary variable to hold the existing/modified character.
      chTemp = "";
      // A new string which will be generated from chTemp.
      stTemp = "";
      // The length of the string being passed in.
      nLength = toString(stData).length;

      // Go through the string character by character.
      for(i = 0; i < nLength; i++)
      {
         // Get the current character and put it in the temp character.
         chTemp = stData.charAt(i);

         // You may need to add more special case characters.
         switch(chTemp)
         {
            case "<"   :   chTemp = "<";  // Replace (<) with (<)
                        break;
            case ">"   :   chTemp = ">";  // Replace (>) with (>)
                        break;
            case "&"   :   chTemp = "&"; // Replace (&) with (&)
                        break;
            case '""'  :   chTemp = "&quot;"; // Replace (") with (&quot;)
                        break;
            default    :   break; // Do nothing, the current character is
                                  // okay.
         }

         // Add the temp character to the end of the temp string.
         stTemp = stTemp + chTemp;
      }

      // Return the properly formatted string.
      return stTemp;
   } 

Additional query words:

Keywords : kbCtrl kbVisID600bug kbGrpASP kbDSupport
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: July 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.