How do I break the a BoundField's HeaderText

回眸只為那壹抹淺笑 提交于 2019-11-29 17:37:43

问题


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.


回答1:


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.




回答2:


For those of you trying to do this without disabling HtmlEncode it's pretty simple, if a little silly looking. Just use a real line break. Like so...

<asp:BoundField DataField="ProposedExtractionStartDate" HeaderText="Proposed
                        Extraction Start Date" SortExpression="ProposedExtractionStartDate"  DataFormatString="{0:MM/dd/yyyy}" />

That will actually come out as multi-line when the HTML renders.

If there is a character combination that will signify this, I would love to know it.



来源:https://stackoverflow.com/questions/310121/how-do-i-break-the-a-boundfields-headertext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!