【发布时间】:2010-03-19 19:35:42
【问题描述】:
a) 据我所知,GridView’s RowStyle-HorizontalAlign 属性应该覆盖 CSS 的 text-align 属性,因此 GridView 单元格内的文本应该位于单元格的左侧,而是移动到右侧。这是为什么呢?
b) 同样,RowStyle-Font-Bold 应该覆盖 CSS 的 font-weight 属性,因此字体不应该是粗体。但同样,CSS 的属性覆盖了RowStyle’s Font-Bold 属性。为什么?
<div id="someClass">
<asp:GridView ID="gvwShowUsers" runat="server" >
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" Font-Bold="false"
HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
</Columns>
</asp:GridView>
</div>
CSS 文件:
#someClass td
{
font-weight:bolder;
text-align:right;
}
感谢
编辑:
解决方法是将样式应用于每个字段(例如 ItemStyle-HorizontalAlign)
我尝试将ItemStyle 应用于GridView’s 字段:
<div id="someClass">
<asp:GridView ID="gvwShowUsers" runat="server" >
<RowStyle Font-Bold="false" HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName">
<ItemStyle HorizontalAlign="Left" Font-Bold="false" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
但是由于即使在应用ItemStyle 之后,页面仍然在单元格的右侧显示文本,所以我决定检查发送给用户的 html 页面的源代码,结果是@987654332 @ 和 <td> 元素将 Align 属性设置为 left,所以...完全糊涂了!
这是一个html页面的源代码:
<table id="GridView1" style="font-weight:normal;">
<tr align="center" style=" font-weight:bold;">
<th scope="col">UserName</th>
</tr>
<tr align="right" valign="bottom" style="font-weight:normal;">
<td align="right" style="font-weight:normal;"> Nancy</td>
</tr>
</table>
【问题讨论】:
-
这对我有用 - 创建一个样式,例如td.left{text-align:left;} 并在绑定字段的 itemstyle 中引用它,例如