Gridview Column Width in ASP.NET 2.0

喜夏-厌秋 提交于 2020-01-02 02:24:06

问题


How do you control the column width in a gridview control in ASP.NET 2.0?


回答1:


You can use the HeaderStyle-Width, ItemStyle-Width or FooterStyle-Width properties. These can be applied to all the columns or per-column basis.

    <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:


I do it using the header style for the column:

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



回答3:


Here's the C# code to do it programatically:

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



回答4:


Gridview.Columns[1].ItemStyle.Width = 100;

This will set the with in pixel.



来源:https://stackoverflow.com/questions/309815/gridview-column-width-in-asp-net-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!