How to insert a new line in the inner text

How can I force a newline (or line break) in the inner text

HtmlGenericControl li; li = new HtmlGenericControl("li"); li.InnerText = sdr.GetValue(0).ToString()+"\n"+sdr.GetValue(1).ToString(); myList.Controls.Add(li); 
+7
source share
3 answers

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

 li.InnerHtml = sdr.GetValue(0).ToString()+"<br />"+sdr.GetValue(1).ToString(); 
+13
source

You can also use the Environment.NewLine property.

Returns the newline specified for this environment.

 li.innerText = sdr.GetValue(0).ToString()+ Environment.NewLine +sdr.GetValue(1).ToString(); 
+2
source

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

 li.InnerHtml = sdr.GetValue(0).ToString()+"<br />"+sdr.GetValue(1).ToString(); 
+1
source

All Articles