Datagrid - Linefeed in header text

  • Thread starter Thread starter Mark B
  • Start date Start date
M

Mark B

How can I put a linefeed in some header text (I am using the Datagrid
control and editing the header properties for a field)?

Average Sales Average Returns Average Sales Average
Returns
(Last 30 Days) (Last 6 Months)
 
Hello Mark,

In order to insert a link break in the header text of a GridView, we need
to disable HtmlEncode of the column. The property HtmlEncode is true by
default. Thus the symbol "<br>" in the HeaderText like "line1<br>line2"
won't serve as a line break. To resolve it, we can set HtmlEncode="false".
For example:

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="line1<br>line2"
HtmlEncode="false" />
</Columns>
</asp:GridView>

If you have any other concerns or questions, please don't hesitate to let
me know.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
It's a template field and giving the following error:

Type 'System.Web.UI.WebControls.TemplateField' does not have a public
property named 'HtmlEncode'.
 
Hello Mark

Template fields do not have the HtmlEncode property. In fact, template
fields do not encode header text, thus we can simply write it as this:

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="line1<br>line2"
HtmlEncode="false" />
<asp:TemplateField HeaderText="line3<br>line4">
</asp:TemplateField>
</Columns>
</asp:GridView>

If you have any other concerns or questions, please don't hesitate to let
me know.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Back
Top