【问题标题】:Gridview Column Width in ASP.NET 2.0ASP.NET 2.0 中的 Gridview 列宽
【发布时间】:2008-11-21 19:04:32
【问题描述】:

如何在 ASP.NET 2.0 的 gridview 控件中控制列宽?

【问题讨论】:

  • Billy,您应该在您的问题中添加一个“asp.net”标签。如果我们这些对这些标签感兴趣的人(更常见),它将在 StackOverflow 中突出显示。谢谢

标签: asp.net gridview


【解决方案1】:

您可以使用 HeaderStyle-Width、ItemStyle-Width 或 FooterStyle-Width 属性。这些可以应用于所有列或每列。

    <asp:GridView ID="GridView1" runat="server">
        <HeaderStyle Width="10%" />
        <RowStyle Width="10%" />
        <FooterStyle Width="10%" />
        <Columns>
            <asp:BoundField HeaderText="Name" DataField="LastName" 
                HeaderStyle-Width="10%" ItemStyle-Width="10%"
                FooterStyle-Width="10%" />
        </Columns>
    </asp:GridView>

【讨论】:

    【解决方案2】:

    我使用列的标题样式来做到这一点:

    <asp:BoundField HeaderText="Name" DataField="LastName">
       <HeaderStyle Width="20em" />
    </asp:BoundField>
    

    【讨论】:

      【解决方案3】:

      这是以编程方式执行此操作的 C# 代码:

      columnName.ItemStyle.Width = Unit.Percentage(someDouble);
      

      【讨论】:

        【解决方案4】:
        Gridview.Columns[1].ItemStyle.Width = 100;
        

        这将以像素为单位设置。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-06
          • 1970-01-01
          • 2019-01-31
          • 1970-01-01
          相关资源
          最近更新 更多