GridView一般换行与强制换行

gridview里有一列绑定的数据很长,显示的时候在一行里面显示,页面拉得很宽。
原因是连续英文段为一个整体导致的,在RowDataBound中添加上了一句:
e.Row.Cells[2].Style.Add("word-break", "break-all")就可以。

//正常换行
GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
//下面这行是自动换行
GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");

总之:善用CSS的word-break:break-all;word-wrap:break-word属性即可,这个属性是通用的对于顽固的难换行或者是需要控制表头的字段不换行问题都可以解决,不局限于GridView。

posted on 2007-09-20 15:41  lbq1221119  阅读(677)  评论(0编辑  收藏  举报

导航