Chris
Chris

Reputation: 2991

ASP.NET Control Styles for Child Controls

On a control like the GridView, you can specify the HeaderStyle attributes as attributes of the GridView element (e.g., HeaderStyle-Wrap="false"), or as an attribute of the HeaderStyle child element. Is one way better than the other? Or, is it just a readability preference?

<asp:GridView ID="myGrid" runat="server" HeaderStyle-Wrap="false" HeaderStyle-HorizontalAlign="Left">
    <!-- Columns -->
</asp:GridView>

or

<asp:GridView ID="myGrid" runat="server">
    <HeaderStyle Wrap="false" HorizontalAlign="Left" />
    <!-- Columns -->
</asp:GridView>

Upvotes: 0

Views: 192

Answers (3)

Chris Mullins
Chris Mullins

Reputation: 6867

I would say that the is more readable if you are setting a lot of the built in style properties. Although I would recommend for the best readability to use CSS to style your grid, and not use the built in properties at all.

My typical grid style usually looks something like this:

<asp:GridView ID="grdTest" runat="server"  CssClass="grid" AlternatingRowStyle-CssClass="altrow">
</asp:GridView>

Then you can use

.grid th
{
     /*style for headings*/
}

.grid td 
{
   /*style for all normal cells */
}

.grid td.altrow
{
  /*style for alternating cells if needed */
}

Upvotes: 1

John Saunders
John Saunders

Reputation: 161773

They are precisely the same thing.

Upvotes: 0

slolife
slolife

Reputation: 19870

I think it is a readability thing and I much prefer the second example, which uses the

 <HeaderStyle />

tag to define header styles

Upvotes: 2

Related Questions