用于子控件的ASP.NET控件样式

时间:2022-01-17 16:50:23

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?

在像GridView这样的控件上,您可以将HeaderStyle属性指定为GridView元素的属性(例如,HeaderStyle-Wrap =“false”),或者指定为HeaderStyle子元素的属性。有一种方式比另一种更好吗?或者,它只是一个可读性偏好?

<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>

3 个解决方案

#1


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

我认为这是一个可读性的东西,我更喜欢第二个例子,它使用了

 <HeaderStyle />

tag to define header styles

用于定义标题样式的标记

#2


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.

我会说,如果你设置了很多内置样式属性,那么它的可读性会更高。虽然我建议最好的可读性使用CSS来设置网格样式,但根本不使用内置属性。

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 */
}

#3


They are precisely the same thing.

它们完全是一回事。

#1


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

我认为这是一个可读性的东西,我更喜欢第二个例子,它使用了

 <HeaderStyle />

tag to define header styles

用于定义标题样式的标记

#2


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.

我会说,如果你设置了很多内置样式属性,那么它的可读性会更高。虽然我建议最好的可读性使用CSS来设置网格样式,但根本不使用内置属性。

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 */
}

#3


They are precisely the same thing.

它们完全是一回事。