How do I break the a BoundField's HeaderText

minty picture minty · Nov 21, 2008 · Viewed 14.6k times · Source

In HTML in the td of a table you can break text by using <BR> between the words. This also works in the HeaderText of a TemplateItem but not the HeaderText of a BoundField. How do I break up the Header text of a BoundField.

Answer

Aleris picture Aleris · Nov 21, 2008

Set HtmlEncode = false inside the BoundField

 <asp:BoundField DataField="SomeDataField" 
        HeaderText="SomeHeader<br />(OtherData)" 
        HtmlEncode="false" />

BoundField.HtmlEncode is true by default which means that if HTML is added in the text it will be encoded.
If HtmlEncode is set to false the text is not encoded and the br will work as expected. Unfortunately is not possible to specify this only for the header text, it will affect the cell contents as well.