3

I.e. im wondering how i can achieve something like

<th><span>Discount</span>PLC</th>

In declaring a gridview columns such as

<asp:TemplateField HeaderText="Discount" HeaderStyle-Width="60px" SortExpression="discount">
  <ItemTemplate>   
    <asp:Label ID="DiscountField" runat="server" Text='<%# Eval("discount").ToString() + "%" %>'></asp:Label>
  </ItemTemplate>                     
</asp:TemplateField> 

How can I add this styling to the header text ?

radbyx
  • 9,352
  • 21
  • 84
  • 127
StevieB
  • 6,263
  • 38
  • 108
  • 193
  • Something some people may find useful - I needed to put a
    in some headertext and couldn't get it working with a TemplateField. So I just used   for all the text except where I wanted the line break - and it worked perfectly. Could be an easy win depending on your requirement.
    – niico Jan 31 '19 at 15:32

3 Answers3

5

Try

 <asp:TemplateField >
        <HeaderTemplate>
             <span>Discount</span>
        </HeaderTemplate>
       <ItemTemplate>   
           <asp:Label ID="DiscountField" runat="server" Text='<%# Eval("discount").ToString() + "%" %>'></asp:Label>
       </ItemTemplate>   

 </asp:TemplateField> 

Make sure <th /> is in context with the table.

Bala R
  • 107,317
  • 23
  • 199
  • 210
  • 1
    I don't believe you want to put the tags in that HeaderTemplate, because it puts whatever is in the template inside tags already. So you'd end up with xxx. – patmortech Aug 16 '11 at 18:06
  • Yeah It does seem to add within anyway around that ? – StevieB Aug 17 '11 at 08:59
0

There is no need of tag inside the header template.It will create a new heading.Template field is already creating a tag.

0

There is no need of header tag inside the header template.It will create a new heading.Template field is already creating a header tag.