8

I cant figure out how to define the width of a particular column of a gridview. I am getting this result:

enter image description here

As you can see, I am getting substantial overflow. I would like to define a maximum width and wrap the test for this 5th column.

I have tried doing it programatically:

    GridView1.Columns[4].ItemStyle.Width = 300;
    GridView1.DataBind();

And also in asp.net:

<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ItemStyle-Width="300px" /> 

or

<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" HeaderStyle-Width="300px"> 

None of these attempts are having any effect.

hutchonoid
  • 32,982
  • 15
  • 99
  • 104
David Tunnell
  • 7,252
  • 20
  • 66
  • 124
  • 1
    You can use an item template, check this post out. [ASP.NET Setting width of DataBound column in GridView](http://stackoverflow.com/questions/8266580/asp-net-setting-width-of-databound-column-in-gridview) – Mike Jul 03 '13 at 19:52

2 Answers2

12

Use the following css class for grid:

.gridView
{
  table-layout:fixed;
}

and on the column use this css class:

.col
{
  word-wrap:break-word;
}
Shashank Chaturvedi
  • 2,756
  • 19
  • 29
1

The text in the top last column has no spaces. This means that the last column will not wrap so the table will stretch. This is just like displaying a really big image that is too big for the container or page.

rgrano
  • 351
  • 1
  • 6