SupremeDud
SupremeDud

Reputation: 1421

How can I render a gridview without ANY style attributes?

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.

Upvotes: 3

Views: 2724

Answers (2)

Oleks
Oleks

Reputation: 32333

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>.

Upvotes: 1

jmaglio
jmaglio

Reputation: 776

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.

Upvotes: 4

Related Questions