0

My page looks correct in Firefox and IE8. But in IE7, a nested gridview spills into the adjacent cell, much like the issue here.

Looking at it in the developer tools, there is an inline-style associated with the table that ASP.NET generated, and it has a width attribute of 100%. If I remove this, the nested table pops back where it belongs.

Problem is, nowhere is an inline-style set. In fact, if I try to set width='250px', it gets overridden with width='100%'. If I try to remove the width attribute in the code-behind, attrGridView.Attributes["Width"] is null, and calling .Remove() does nothing. But every asp.net-generated gridview-table has an inline style with width='100%' set on it (it's only causing me issues in one place).

Setting table-layout='fixed', as suggested in the article I linked to, did not help.

How do I get ASP.NET to stop setting this property?


Some code:

<asp:TemplateField HeaderText="Attributes" SortExpression="Attributes">
  <HeaderStyle CssClass="GridHeaderCell" />
  <ItemStyle CssClass="GridTableCell AttrGridCellPadding" />
  <ItemTemplate>

    <asp:GridView id="attributesGridView" runat="server"
         AutoGenerateColumns="false" ShowHeader="false" GridLines="None" 
         AlternatingRowStyle-BackColor="White" CssClass="StupidGridView" > 

      <EmptyDataTemplate>
        <p class="italic">There are no attributes for this request.</p>
      </EmptyDataTemplate>

      <Columns>
        <asp:TemplateField>
          <ItemStyle CssClass="AttrTableCell" />
          <ItemTemplate>
            <asp:Label id="attributeName" runat="server" 
                 Text='<%# Eval("Name") + ":&nbsp;&nbsp; "+ Eval("Value") %>'
                 CssClass="AttrGridCell"></asp:Label>
          </ItemTemplate>
        </asp:TemplateField>
      </Columns>

    </asp:GridView>
  </ItemTemplate>
</asp:TemplateField>


.StupidGridView {
  width:  250px;
}
Community
  • 1
  • 1
James King
  • 6,233
  • 5
  • 42
  • 63
  • do you have a theme specified anywhere? if a theme is being applied to the gridview it's possible it would overwrite control-level settings. – lincolnk Nov 01 '10 at 21:19
  • lincolnk, you nailed it! I'm not using gridview themes, but someone else in the project is. I can override that on my gridviews, no problem. If you post as an answer, I'll mark it as correct. Thanks! – James King Nov 01 '10 at 21:44

2 Answers2

2

Themes are being applied and overriding control-level settings. Check theme settings on page, web.config, or anywhere else a theme may be set.

lincolnk
  • 11,218
  • 4
  • 40
  • 61
1

Unfortunately, the ASP.NET html rendering is really bad. Microsoft know that and provided Control adapters in 2006 which allow you to modify control rendering.

Instead of searching on how to override what ASP.NET render, I would advise to use CSSFriendly which provides control adapters for most ASP.NET bad-rendered controls.

If you don't need "pure-css rendering" and CSS afraid you, you can check how they do to create your own adapter.

ScottGu post on this subject from google.

JoeBilly
  • 3,057
  • 29
  • 35
  • Upvoted for the Control Adapter suggestion and link to Scott Gu's article. I will definitely look more into this! – James King Nov 02 '10 at 15:45