Show line breaks in asp:label inside gridview

Posted by Vipin on Geeks with Blogs See other posts from Geeks with Blogs or by Vipin
Published on Thu, 22 Mar 2012 15:02:45 GMT Indexed on 2012/03/22 17:31 UTC
Read the original article Hit count: 283

Filed under:

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;

}

© Geeks with Blogs or respective owner