3

Here's my aspx:

<asp:GridView ID="GVWOReport" runat="server" DataSourceID="ldsWOReport" 
    onprerender="GVWOReport_PreRender" GridLines="None" CssClass="report" >
    <HeaderStyle CssClass="headerRow" />
    <RowStyle CssClass="row" />
    <AlternatingRowStyle CssClass="altRow" />
    <FooterStyle CssClass="footer" />
</asp:GridView>

Here's my rendered HTML:

<table class="report" cellspacing="0" id="GVWOReport" style="border-collapse:collapse;">
    <thead>...</thead>
    <tbody>...</tbody>
</table>

I want the table tag to have nothing but my class and id attributes. I found out that the GridLines="None" takes away the border, but I can't get the cellspacing and style to go away.

Cœur
  • 37,241
  • 25
  • 195
  • 267
SupremeDud
  • 1,371
  • 10
  • 18

2 Answers2

4

Set the CellSpacing property to -1 in design view. I don't get any style or cellspacing attributes after doing that. I am using asp.net 4.0.

jmaglio
  • 766
  • 6
  • 11
1

Take a look at GridView Control Adapter: ASP.NET 2.0 CSS Friendly Control Adapters 1.0. If offers even more functionality than you need:

The goal of the adapter for the GridView control is to create a <table> that is slimmer and better organized than what is produced without the adapter. You could, of course, rewrite this adapter to completely eliminate the <table>, replacing it with a variety of <div> tags, etc. However, a grid, fundamentally, is a table so it seems logical to leave it as such.

The adapted GridView eliminates the use of inline styles. Rows within the <table> are organized into <thead>, <tfoot> and <tbody> sections. These make it easier to read and understand the markup. More importantly, these sections make it easy to create CSS rules that govern the appearance of particular rows within the <table>.

Oleks
  • 31,955
  • 11
  • 77
  • 132
  • 2
    Use these if you are using asp.net 2.0. If you are using asp.net 4.0, the controls are css friendly for the most part - you just have to set the properties accordingly. If you set Gridlines="None" and CellSpacing="-1", your Gridview will just be a table tag with an ID. – jmaglio Mar 04 '12 at 17:06