GridView, border-collapse, IE, and empty-cells

I came across two issues with Microsoft applications while trying to eliminating vertical cell borders in HTML tables using CSS.

GridView and border-collapse

ASP.Net 2.0’s GridView always emits something like the following:

<table style="border-collapse:collapse;" >

Turns out GridView is hardcoded to emit the style attribute and there is no way to override the behavior in layout [reference, reference].

There is no way to remove the extra attribute, but I found a workaround [reference] that results in something like this:

<table style="border-collapse:collapse;border-collapse:separate;">

IE and empty-cells

Internet Explorer 7 does not support empty-cells [reference]. Confirmed it.

So Simple It Hurts

In the end I achieved the desired table formatting without having to worry about border-collapse or empty-cells. All I needed was something like this:

tr { border-top: hidden; }
td { border-width: 0px 1px 0px 0px; }

2 Responses to this post.

  1. Another way to do it is to override the style using the ! important keyword(s) in your own CSS class. I explain how here: http://justgeeks.blogspot.com/2008/09/override-any-css-style-even-inline.html. I’m not sure which solution I like better though. Hmmm….

    Reply

  2. Posted by tibx on November 24, 2008 at 16:38

    try GridLines=”None” CellSpacing=”-1″

    Reply

Respond to this post