Archive for June, 2008|Monthly archive page

replacing Alt Enter character in Excel with HTML line break in a DataList

Problem: Excel cells contain Alt+Enter line breaks. After the Excel file is imported to the SQL Server database, the line break is not showing in a datalist inside of a webpage.


Trigger a function for the ItemDataBound event for the DataList. Replace the Alt+Enter character in Excel which is “\n” with HTML line break “<br />”


protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)

String temp = ((Label)e.Item.FindControl(“YourControlName”)).Text;

((Label)e.Item.FindControl(“YourControlName “)).Text = temp.Replace(“\n”, “<br />”);