Line break in GridView Header Text

S

sck10

Hello,

I have the following for a GridView. How do you break the HeaderText into
two lines. I tried using:

HeaderText="Revenue <br /> Impact", but that doesn't work. Any help would
be appreciated.
--
Thanks in advance,

sck10


<asp:BoundField DataField="RevenueImpactType"
HeaderText="Revenue Impact"
SortExpression="RevenueImpactType"
ItemStyle-HorizontalAlign="Left"
ItemStyle-VerticalAlign="Top"
ItemStyle-Width="15%"
FooterStyle-BorderWidth="0" />
 
W

Walter Wang [MSFT]

Hi,

Thank you for posting!

Based on my understanding, the question is: how to prevent the GridView
from encoding HeaderText property. If there's anything I misunderstood,
please feel free to post here.

Well, while we cannot prevent GridView from encoding the HeaderText
property, we can decode it back after the DataBinding is complete. We can
do this in the DataBound event:

protected void CustomersGridView_DataBound(object sender, EventArgs e)
{
foreach (TableCell c in CustomersGridView.HeaderRow.Cells)
{
c.Text = HttpUtility.HtmlDecode(c.Text);
}
}

If there is any unclear/you have any more concerns, please feel free to
reply here. I am glad to work with you on it.

Thanks.


Regards,

Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Walter Wang [MSFT]

Hi,

Sorry for the last post. I overlooked that there is a property named
"HtmlEncode" in BoundField to indicate whether field values are
HTML-encoded before they are displayed.

So the correct answer to your question would be:

<asp:BoundField DataField="RevenueImpactType"
HeaderText="Revenue Impact"
HtmlEncode="false"
SortExpression="RevenueImpactType"
ItemStyle-HorizontalAlign="Left"
ItemStyle-VerticalAlign="Top"
ItemStyle-Width="15%"
FooterStyle-BorderWidth="0" />



Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Joined
Dec 15, 2010
Messages
1
Reaction score
0
If the column is not a bound field.

How to force line break in the Headertext in item template of a data grid?
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top