GridView一般换行与强制换行


效果图:

  首先设置<asp:BoundField DataField="家庭住址" HeaderText="家庭住址"  ItemStyle-Width="100" />

  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)
        {
             bind();//调用数据绑定即可
        }
    }

  总之:善用CSS的word-break:break-
all;word-wrap:break-word属性即可,这个属性是通用的对于顽固的南换行问题都可以解决,不局限于GridView。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3