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 ?

1
  • Something some people may find useful - I needed to put a <br /> in some headertext and couldn't get it working with a TemplateField. So I just used &nbsp; for all the text except where I wanted the line break - and it worked perfectly. Could be an easy win depending on your requirement. Commented Jan 31, 2019 at 15:32

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't believe you want to put the <th> tags in that HeaderTemplate, because it puts whatever is in the template inside <th> tags already. So you'd end up with <th><th>xxx</th></th>.
Yeah It does seem to add <th> within <th> anyway around that ?
0

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.