C# 如何打破 BoundField 的 HeaderText

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/310121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 22:40:11  来源:igfitidea点击:

How do I break the a BoundField's HeaderText

c#gridviewboundfieldheadertext

提问by minty

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.

在表格的 td 中的 HTML 中,您可以通过<BR>在单词之间使用来中断文本。这也适用于 TemplateItem 的 HeaderText 但不适用于 BoundField 的 HeaderText。如何分解 BoundField 的标题文本。

采纳答案by Aleris

Set HtmlEncode = falseinside the BoundField

设置HtmlEncode = false里面的BoundField

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

BoundField.HtmlEncodeis 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.

BoundField.HtmlEncode默认情况下为 true,这意味着如果在文本中添加 HTML,它将被编码。
如果 HtmlEncode 设置为 false,则不会对文本进行编码,并且 br 将按预期工作。不幸的是,不可能只为标题文本指定此项,它也会影响单元格内​​容。

回答by Tom Padilla

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...

对于那些试图在不禁用 HtmlEncode 的情况下执行此操作的人来说,这非常简单,尽管看起来有点傻。只需使用真正的换行符。像这样...

<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.

当 HTML 呈现时,这实际上会以多行形式出现。

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

如果有一个字符组合可以表示这一点,我很想知道。