Billy
Billy

Reputation:

Gridview Column Width in ASP.NET 2.0

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

Upvotes: 8

Views: 36344

Answers (4)

Microsoft Developer
Microsoft Developer

Reputation: 5459

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

This will set the with in pixel.

Upvotes: 0

dProvencher
dProvencher

Reputation: 31

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

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

Upvotes: 3

achinda99
achinda99

Reputation: 5078

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>

Upvotes: 8

DCNYAM
DCNYAM

Reputation: 12126

I do it using the header style for the column:

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

Upvotes: 3

Related Questions