BUG: Grid DTC Interprets HTML Tag as HTML (192033)



The information in this article applies to:

  • Microsoft Visual Studio, Enterprise Edition 6.0

This article was previously published under Q192033

SYMPTOMS

The Grid Design-Time Control (DTC) interprets a table that contains an HTML tag such as <HR> as HTML rather than text. In this case, a horizontal rule is displayed in the cells 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 must 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, notice the Field/expression text box. If you prefix the data in this field with an equal sign ("="), it is interpreted as JavaScript. If you enclose the name of a field with square brackets ("[]"), the grid displays 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:

    =Server.HTMLEncode([fieldname])

    For DHTML (client-side), it is necessary to write a function to convert the string to display properly:

    example: =MyHTMLEncode([field1])

    See the example in MORE INFORMATION section.
  2. Format the data in the database so it displays properly (<HR> rather than <HR>).

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

A sample HTMLEscape() function:
   // This function is time-consuming, and it is 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;
   }
				

Modification Type:MinorLast Reviewed:8/11/2005
Keywords:kbBug kbCtrl kbpending KB192033