GridView里有一列绑定的数据很长,显示的时候在一行里面显示,页面拉得很宽。
原因是连续英文段为一个整体导致的,在RowDataBound中添加上了一句e.Row.Cells[2].Style.Add("word-break", "break-all")就可以。如果要给所有的列增加此属性:
- protected void Page_Load(object sender, EventArgs e)
- {
- //正常换行
- GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
- //下面这行是自动换行
- GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
- if (!IsPostBack)
- {
- databind();
- }
- }