views:

79

answers:

3

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>
+2  A: 

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

 <HeaderStyle />

tag to define header styles

slolife
A: 

They are precisely the same thing.

John Saunders
+1  A: 

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 */
}
Chris Mullins
or asp.net skins
Chris Dwyer