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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值