代码改变世界

SPGridView字段(单元格)换行

2010-04-18 00:11  Leason Li  阅读(330)  评论(0编辑  收藏  举报


前台:

   <asp:BoundField DataField="Integral" HeaderText="积分" />   

后台:

 

dr["CompanyName"+= dt.Rows[j]["CompanyName"].ToString() + "\n";
代码
    protected void SPGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[
1].Text = KeepPre(e.Row.Cells[1].Text);
            }

    }
代码
    public string KeepPre(string html)
    {
        
if (string.IsNullOrEmpty(html))
        {
            
return html;
        }
        html 
= html.Replace("\n""<br/>");
        
return html;
    }