Line break in GridView Header Text

  • Thread starter Thread starter sck10
  • Start date Start date
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" />
 
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.
 
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.
 
Back
Top