Show line breaks in asp:label inside gridview
- by Vipin
To show line breaks in asp:label element or for that matter inside Gridview, do the following in case of Mandatory/ Nullable fields.
<ItemTemplate> <%# ((string)Eval("Details")).Replace("\n", "<br/>") %> </ItemTemplate> <ItemTemplate> <%# FormatString(Eval("Details")) %> </ItemTemplate>
In code behind, add the following FormatString function -
protected string FormatString(string strHelpMessage)
{
string rtnString = string.Empty;
if (!string.IsNullOrEmpty(strHelpMessage))
rtnString = strHelpMessage.Replace(Environment.NewLine, "<br/>");
return rtnString;
}