简体   繁体   English

为GridView列和Wrap Text创建最大宽度

[英]Creating max width for GridView column and Wrap Text

I cant figure out how to define the width of a particular column of a gridview. 我无法弄清楚如何定义gridview的特定列的宽度。 I am getting this result: 我得到了这个结果:

在此输入图像描述

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. 我想定义一个最大宽度并包装第5列的测试。

I have tried doing it programatically: 我试过以编程方式做到这一点:

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

And also in asp.net: 而且在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. 这些尝试都没有任何效果。

Use the following css class for grid: 对网格使用以下css类:

.gridView
{
  table-layout:fixed;
}

and on the column use this css class: 并在列上使用此css类:

.col
{
  word-wrap:break-word;
}

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. 这就像显示一个对容器或页面来说太大的非常大的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM