代码之家  ›  专栏  ›  技术社区  ›  James King

GridView生成的代码将“width=”100%“添加到它创建的表中

  •  0
  • James King  · 技术社区  · 14 年前

    here .

    在开发人员工具中,有一个与ASP.NET生成的表相关联的内联样式,它的width属性为100%。如果删除此项,嵌套表将弹出回其所属位置。

    问题是,没有内联样式集。事实上,如果我试着 width='250px' width='100%' . 如果我试图删除后面代码中的width属性, attrGridView.Attributes["Width"] 为空,正在调用 .Remove() 什么都不做。但是每个asp.net生成的gridview表都有一个内联样式 开始吧(这只会在一个地方给我带来麻烦)。

    设置 table-layout='fixed'

    如何使ASP.NET停止设置此属性?


    一些代码:

    <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;
    }
    
    2 回复  |  直到 8 年前
        1
  •  2
  •   lincolnk    14 年前

    正在应用主题并覆盖控件级设置。检查页面、web.config或其他任何可能设置主题的位置上的主题设置。

        2
  •  1
  •   JoeBilly    14 年前

    不幸的是,ASP.NET html呈现非常糟糕。 微软知道这一点并提供了 Control adapters 在2006年,它允许您修改控件呈现。

    CSSFriendly 它为大多数ASP.NET错误呈现控件提供控件适配器。

    ScottGu post on this subject 来自谷歌。