Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a new line in innertext

Tags:

c#

asp.net

How will I be able to force a newline(or a line break) in innertext

HtmlGenericControl li;
li = new HtmlGenericControl("li");
li.InnerText = sdr.GetValue(0).ToString()+"\n"+sdr.GetValue(1).ToString();      
myList.Controls.Add(li);
like image 652
user1692773 Avatar asked Jan 22 '13 10:01

user1692773


3 Answers

Use <br /> html tag for line break instead of \n and use innerHtml instead of innerText

li.InnerHtml = sdr.GetValue(0).ToString()+"<br />"+sdr.GetValue(1).ToString(); 
like image 107
Adil Avatar answered Sep 28 '22 14:09

Adil


You can use with Environment.NewLine property also.

Gets the newline string defined for this environment.

li.innerText = sdr.GetValue(0).ToString()+ Environment.NewLine +sdr.GetValue(1).ToString(); 
like image 37
Soner Gönül Avatar answered Sep 28 '22 13:09

Soner Gönül


You can use li.InnerHtml property and <br /> for next line.

li.InnerHtml = sdr.GetValue(0).ToString()+"<br />"+sdr.GetValue(1).ToString();
like image 41
TechDo Avatar answered Sep 28 '22 13:09

TechDo