您的位置:首页 > 其它

gridview列内容自动换行的方法

2009-08-25 16:55 344 查看
001-0004 gridview列内容自动换行的方法





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



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/czw_mr/archive/2009/05/06/4155484.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: