ASP.NET GridView中文本内容无法换行


第一类:自动换行

GridView默认是自动换行,就是说当显示的字符串比较长的时候,GridView会自动换行。

如果我们不想让它自动换行,在页面后台添加如下代码即可:

//正常换行 
GridView1.Attributes.Add("style","word-break:keep-all;word-wrap:normal");

第二类:正常换行

1、应该使用 "<br/>"

2、
①如果你绑定字段为设置模版列,那么把对应的BoundField设置参数HtmlEncode= "false" 即可。

②如果为自动生成字段:请添加GridView1_RowDataBound事件

/// <summary> 
/// 使得GridView中的内容可以换行 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e) 

    if (e.Row.RowType == DataControlRowType.DataRow) 
    {  
        TableCellCollection cells = e.Row.Cells; 
        foreach (TableCell cell in cells) 
        { 
            cell.Text = Server.HtmlDecode(cell.Text); 
        } 
    } 
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM