1.文本框多行输入换行保存后,用GridView显示换行和文本框显示效果一样。
效果图:
方法:
1.进行保存的时候先把文本框内容进行转换:
txtworkrecord.Text = txtworkrecord.Text.Replace("\r\n", "<br>");2.GridView的RowDataBound事件
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCellCollection cells = e.Row.Cells;
string dd = cells[3].Text;
cells[3].Text = Server.HtmlDecode(cells[3].Text); //从0开始算,我要换的是第四列也就是cells[3]
//foreach (TableCell cell in cells)
//{
// cell.Text = Server.HtmlDecode(cell.Text); //注意:如果是每行用foreach循环一下就可以了
//}
}
}

本文介绍了一种在GridView中正确显示多行文本的方法,通过将文本框中的换行符替换为HTML的换行标签,再利用RowDataBound事件对单元格内容进行解码,实现了与文本框一致的换行显示效果。
5879

被折叠的 条评论
为什么被折叠?



