Internal gridlines in GridView in ASP.NET
I have a GridView
in ASP.NET 2.0 that I wan开发者_开发知识库t to have show only internal gridlines. Here is my markup and CSS so far:
<asp:GridView ID="myGrid" runat="server" GridLines="None" CssClass="myDataGridClass">
<Columns>
...columns here...
</Columns>
</asp:GridView>
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;
}
Am I right in thinking that there must be an easier way to do this? My method above already does not work in IE, since I'm using last-child
.
protected void Page_Load(object sender, EventArgs e)
{
this.myGrid.Attributes.Add("bordercolor", "#000");
}
With the GridView, the declarative bordercolor attribute adds an inline style declaration which only applies to the table itself, not individual cells.
Adding the bordercolor attribute programmatically does not use an inline style, but uses the HTML bordercolor property, which browsers apply to ALL borders inside the table.
See comments under this blog post:
http://codersbarn.com/post/2009/05/31/Set-Color-of-GridLines-in-Gridview.aspx
GridLines="None" CellSpacing="2" BackColor="White"
精彩评论