My thoughts regarding ASP.NET, C#, programming practices, and more...
reading
You Should Read archives
blogs I read
|
Tuesday, September 19, 2006Gridview: Convert /n line breaks to html br line breaks
It has been awhile since I have manipulated data in a Gridview. I am binding a collection to a Gridview and one of the values contains non-html line breaks (\n). I would like to convert these to html line breaks (<br />). The code below works fine:
Content copyright ©2003-2006 Tod Birdsall
166 protected void gridHistory_RowDataBound(object sender, GridViewRowEventArgs e) 167 { 168 GridViewRow row = e.Row; 169 if (e.Row.RowType == DataControlRowType.DataRow) 170 { 171 row.Cells[0].Text = row.Cells[0].Text.Replace("\n", "<br />"); 172 } 173 } I was wondering if there is an "easier"/"better" way of doing this, so I posted the question at the ASP.NET forums. Feel free to post your comments to that thread, rather than this blog entry. Update Aaron at ASP.NET provided me with a more aesthitic solution. See the code below:
|