GridView header column text getting html encoded

  • Thread starter Thread starter TS
  • Start date Start date
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?
 
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.
 
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
 
Back
Top