在RowCreated事件中添加
e.Row.Cells[6].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");
这样则会让你选定的列自动换行了 不过前提是要给列设置宽度
<asp:BoundField DataField="Memo" HeaderText="备注" >
<ItemStyle Width="20%" Wrap="True" />
</asp:BoundField>
前台这样写。 注意: Wrap="True" 啊!
--------------------------------------------------------------------------------------------------------------------
在页面加入属性:style =" word-break :break-all ; word-wrap:break-word " (table或div 等的属性里)
或设置
protected void GridView1_DataRowBound(object o, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//设置要换行的模板列
e.Row.Cells[0].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");
e.Row.Cells[1].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");
}
}
--------------------------------------------------------------------------------------------------------------------
在GridView的数据绷定中的添加如下事件:
也就是给GridView的每行动态添加上Style的属性和其对应的属性植.
protected void ADCGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//word-break:break-all;
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("Style", "word-break:break-all;");
}
}
}
--------------------------------------------------------------------------------------------------------------------
GridView强制换行与自动换行
在PageLoad中加入如下代码:
//正常换行
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();//调用数据绑定即可
}