StevieB
StevieB

Reputation: 6541

ASP.NET Add HTML To Gridview header Text

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 ?

Upvotes: 3

Views: 7320

Answers (3)

Bala R
Bala R

Reputation: 109027

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.

Upvotes: 6

Kunal Patidar
Kunal Patidar

Reputation: 3

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.

Upvotes: 0

Kunal Patidar
Kunal Patidar

Reputation: 1

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

Upvotes: 0

Related Questions