ASP.NET中GridView的内部网格线

Tom*_*ing 2 css asp.net internet-explorer cross-browser

我有一个GridViewASP.NET 2.0,我想只显示内部网格线.到目前为止,这是我的标记和CSS:

<asp:GridView ID="myGrid" runat="server" GridLines="None" CssClass="myDataGridClass">
    <Columns>
        ...columns here...
    </Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)

CSS:

.myDataGridClass>tbody>tr>td /* Apply border to all cells */
{
   border:1px solid black;
}

.myDataGridClass>tbody>tr>th /* Apply border to headers */
{
   border:1px solid black;
}

.myDataGridClass>tbody>tr>td:last-child /* Remove right-side border */
{
   border-right-width:0;
}

.myDataGridClass>tbody>tr>td:first-child /* Remove left-side border */
{
   border-left-width:0;
}

.myDataGridClass>tbody>tr>th:last-child /* Remove right-side header border */
{
   border-right-width:0;
}

.myDataGridClass>tbody>tr>th:first-child /* Remove left-side header border */
{
   border-left-width:0;
}

.myDataGridClass>tbody>tr:last-child>td /* Remove bottom border */
{
    border-bottom-width:0;
}

.myDataGridClass>tbody>tr>th /* Remove top border */
{
   border-top-width:0;
}
Run Code Online (Sandbox Code Playgroud)

我是否正确地认为必须有一种更简单的方法来做到这一点?我上面的方法已经不适用于IE,因为我正在使用last-child.

Iri*_*ain 5

protected void Page_Load(object sender, EventArgs e)
{
    this.myGrid.Attributes.Add("bordercolor", "#000");
}
Run Code Online (Sandbox Code Playgroud)

使用GridView,声明性bordercolor属性添加内联样式声明,该声明仅适用于表本身,而不是单个单元格.

以编程方式添加bordercolor属性不使用内联样式,而是使用HTML bordercolor属性,这些属性适用于表中的所有边框.

请参阅此博客文章下的评论:

http://codersbarn.com/post/2009/05/31/Set-Color-of-GridLines-in-Gridview.aspx