Cleaning up Default GridView Markup

I saw an interesting question today from a customer related to some of the default markup for a GridView. The following code:

<asp:GridView ID="GridView1" runat="server">

Will generate this markup in the web page:

<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">



CellSpacing="-1" GridLines="None"

Will clean the markup considerably generating this in the web page:

<table border="0" id="GridView1">

There currently is no way to get rid of the final Border="0" but the above technique does clean up the table considerably.

Comments (1)
  1. Darryl says:

    This is not the entire story.  Setting CellSpacing=-1 removes the border-collapse, but then you have no way of removing the default CellSpacing of 1 in IE.  MS won't change this for backward compatibility (IOW, perpetuate an unwieldy control).

Comments are closed.

Skip to main content