【问题标题】:Set Width of Cells of Grid View?设置网格视图的单元格宽度?
【发布时间】:2012-09-05 05:53:49
【问题描述】:

我有网格视图,现在我想为每个单元格设置特定宽度,我尽我所能设置每个单元格的宽度,但没有这样做...

这是我应用于模板字段的代码。

<ItemTemplate>
<asp:Label ID="lblempid" runat="server" Text='<%#Eval("EmployeeId") %>'></asp:Label>
<ControlStyle Height="10px" Width="20px" />
</ItemTemplate>

我是 c# 和 ASP.Net 的新手,所以请指导我。

提前致谢。 :)

【问题讨论】:

  • 是的,经过一点修改后它就可以工作了:)

标签: asp.net c#-4.0 gridview


【解决方案1】:

你可以这样设置

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

  int colWidth = 100;
  if (colWidth > 0)
  {
    for (int i = 0; i < GridView1.Columns.Count; i++)
    {
      GridView1.Columns[i].ItemStyle.Width = colWidth;
    }
  }
}

【讨论】:

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