Format DataGrid Text

A

Arpan

How do I format only the Header text (column names) in a DataGrid? Consider the following code snippet:

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label id="fname" Text=<%# Container.DataItem("FirstName") %> runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Address" DataField="Address" runat="server"/>
<asp:BoundColumn HeaderText="City" DataField="City" runat="server"/>
.............
.............
.............

How do I format (like make it bold or italicize) the Headers "Name","Address" & "City"? I want to format ONLY the Headers, not anything else that the DataGrid displays.

Please note that I am working on Windows 2000 Professional.

Thanks,

Arpan
 
G

Guest

You can create a style in a style sheet and assign it to the datagrid's
headerstyle-cssclass property.

e.g.

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false"
runat="server" HeaderStyle-CssClass="myClassName">

Alternatively you can use the datagrid's various headerstyle- properties.

e.g.

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false"
runat="server" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Italic="True">

HTH

Alan
 
E

Eliyahu Goldin

Arpan,

DataGrid has a bunch of attributes with the names starting on HeaderStyle-...

Eliyahu

How do I format only the Header text (column names) in a DataGrid? Consider the following code snippet:

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label id="fname" Text=<%# Container.DataItem("FirstName") %> runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Address" DataField="Address" runat="server"/>
<asp:BoundColumn HeaderText="City" DataField="City" runat="server"/>
............
............
............

How do I format (like make it bold or italicize) the Headers "Name","Address" & "City"? I want to format ONLY the Headers, not anything else that the DataGrid displays.

Please note that I am working on Windows 2000 Professional.

Thanks,

Arpan
 
S

Shiva

Use the HeaderStyle property. E.g.:

<asp:DataGrid ID='xx' Runat=server>
....
<HeaderStyle Font-Bold=True Font-Name='Arial'></HeaderStyle>
....
</asp:DataGrid>

How do I format only the Header text (column names) in a DataGrid? Consider
the following code snippet:

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label id="fname" Text=<%# Container.DataItem("FirstName") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Address" DataField="Address" runat="server"/>
<asp:BoundColumn HeaderText="City" DataField="City" runat="server"/>
.............
.............
.............

How do I format (like make it bold or italicize) the Headers
"Name","Address" & "City"? I want to format ONLY the Headers, not anything
else that the DataGrid displays.

Please note that I am working on Windows 2000 Professional.

Thanks,

Arpan
 
A

Arpan

Thanks, Alan, for your suggestion. Thanks to Eliyahu & Shiva as well!
Regards,

Arpan
You can create a style in a style sheet and assign it to the datagrid's
headerstyle-cssclass property.

e.g.

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false"
runat="server" HeaderStyle-CssClass="myClassName">

Alternatively you can use the datagrid's various headerstyle- properties.

e.g.

<asp:DataGrid id="myDataGrid" GridLines="both" AutoGenerateColumns="false"
runat="server" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Italic="True">

HTH

Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top