How do I change the defualt of 0 for the padding in the Gridview's table? RRS feed

  • Question

  • User-1833980242 posted

    I am trying to style the table rendered by a gridview.  This is rendered using the CSS friendly control adapters.  They don't seem to be too CSS Friendly in this case.

    This is the html that is rendered using the control adapters:

    <table cellpadding="0" cellspacing="0" summary="">

    <div class="AspNet-GridView">

    <table cellpadding="0" cellspacing="0" summary="">

    ........rest of table stuff....................



    I want to add  little padding to the left and right of the <td>s.  I tried to do this several different ways but couldn't get it to work.

    This is the CSS I tried:

    .AspNet-GridView td


        padding-left: 8px;   

        padding-right: 8px;  

        margin-left: 8px;   

        margin-right: 8px;   


    .AspNet-GridView th


       padding-left: 8px;   

       padding-right: 8px;   


    My conclusion is that this won't work because of the inline styles that are rendered by the control adapter.  They set the cellpadding and cellspacing to "0" in the html for the table (see html above).  From what I understand,  inline trumps external styles.  

    Does anyone know how I can get around this, without building my own control adapters? Nothing I try works.

    Tuesday, August 11, 2009 6:21 PM

All replies

  • User1446264833 posted

     Set the CSS inline with your GridView, something like this,

        <asp:GridView ID="GridView1" runat="server" style="padding-left:8px; padding-right: 8px; margin-left: 8px; margin-right:8px;">


    Tuesday, August 11, 2009 6:48 PM