Datagrid - Linefeed in header text

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)
 
J

Jialiang Ge [MSFT]

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

Mark B

It's a template field and giving the following error:

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

Jialiang Ge [MSFT]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top