GridView header column text getting html encoded

T

TS

I have a headerText for a header column that is "Page<br>Name". it puts a
<br> to force a line break, but the < and > get encoded to &lt; and &gt;
thus negating its effect as an html control and doesn't respect the line
break

I'm guessing this happens during render. What do i need to do to keep the
line break?
 
S

Steven Cheng[MSFT]

Hi TS,

As for the text in the GridView header column, how did you put in to it?
Statically or dynamically through databinding? I've tested put static test
<br/> into TemplateField's HeaderTemplate and it can be displayed correctly
as linebreak. e.g.

==============
...................
<HeaderTemplate>
Page<br />Name
<hr />
Page&lt;br&gt;Name
</HeaderTemplate>

<ItemTemplate>
<%# Eval("description")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>

</asp:GridView>
================

Also, based on the test, if the text is from databinding source and
displayed in TemplateField, since it does not htmlencode it bydefault,
<br/> can also display correctly as linebreak.

Please feel free to let me know if there is anything I missed or if you
have any further concerns.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

marss

TS said:
I have a headerText for a header column that is "Page<br>Name". it puts a
<br> to force a line break, but the < and > get encoded to &lt; and &gt;
thus negating its effect as an html control and doesn't respect the line
break

I'm guessing this happens during render. What do i need to do to keep the
line break?

If you use BoundField then set HtmlEncode to false
<asp:BoundField DataField="..." HeaderText="Page<br>Name"
HtmlEncode="false"/>

Regards,
Mykola
http://marss.co.ua
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top