Reputation: 3369
I want to do something in CSS specific to the first element in the table headers row but I don't want to have tot rely on :first_child.
Code:
<asp:TemplateColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>
<span><asp:Literal id="header" runat="server" Text="<%$ Resources:index, IndexSearch_Header_Product %>" /></span>
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink runat="server" ID="productLink" />
</ItemTemplate>
</asp:TemplateColumn>
Where can I add an ID (for CSS) on the td/th itself?
Upvotes: 0
Views: 514
Reputation: 41
Use GridView instead of DataGrid. GridView renders header as 'th' tag (not 'td').
So, assuming you set CssClass="myGrid" to GridView you can decorate your header by this CSS selector:
table.myGrid tr th
{
background-color: blue;
}
Upvotes: 0
Reputation: 1996
You can add the required class in the TemplateColumn as HeaderStyle-CssClass attribute. Check the below code.
<asp:TemplateColumn HeaderStyle-CssClass="firstheaderclass" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>
<span><asp:Literal id="header" runat="server" Text="<%$ Resources:index, IndexSearch_Header_Product %>" /></span>
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink runat="server" ID="productLink" />
</ItemTemplate>
</asp:TemplateColumn>
But if you want to add an ID attribute to the first header of Datagrid, you have to do it in code behind and adding the ID attribute to the First header cell
Just give it a try ;-)
Upvotes: 1
Reputation: 12904
Not sure you can. Create a named css class and assign this to your content within the HeaderTemplate.
Upvotes: 0