Microsoft Knowledge Base Email Alertz

A string may not be formatted correctly when you try to format the string by using the DataFormatString property of the BoundField class in the DataView control in the .NET Framework 2.0

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 916441 - Last Review: December 3, 2007 - Revision: 1.3

A string may not be formatted correctly when you try to format the string by using the DataFormatString property of the BoundField class in the DataView control in the .NET Framework 2.0

SYMPTOMS

You try to format a string by using the DataFormatString property of the BoundField class in the DataView control. When you do this, the string may not be formatted correctly. This behavior may occur when the Web application is built on the Microsoft .NET Framework 2.0.

Note This behavior does not occur when you use the .NET Framework 2.0 Beta 2 or earlier versions of the .NET Framework.

CAUSE

This behavior occurs because the data is automatically encoded before the string formatting is applied. By default, the HtmlEncode property of the BoundField class in the DataView control is set to True. The HtmlEncode property is set to True to encode the string data. When the HtmlEncode property is set to True, unsafe script from the data store cannot be displayed on the client computer. This feature of the .NET Framework helps protect the client computer from cross-site scripting attacks.

RESOLUTION

To resolve this behavior, set the HtmlEncode property of the BoundField class in the DataView control to False. Alternatively, use a TemplateField control instead.

STATUS

This behavior is by design.

MORE INFORMATION

For more information about how to use the BoundField class, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.aspx (http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.aspx)
For more information about how to use the DataView class, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/system.data.dataview(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.data.dataview(vs.71).aspx)
For more information about how to use the BoundColumn class, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundcolumn.aspx (http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundcolumn.aspx)
For more information about how to use the TemplateField class, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.aspx (http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.aspx)

APPLIES TO
  • Microsoft .NET Framework 2.0
Keywords: 
kbtshoot kbnofix kbprb KB916441
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate