Insert spaces between characters in a list

I am trying to insert elements into a list in my asp.net c # application

I combine some values ​​and put a space between them, but it does not appear in the list.

ListItem lt = new ListItem(); lt.Text = ItemName + " " + barcode + " " + price; // problem lt.Value = barcode; lstMailItems.Items.Add(lt); 

I even tried

 lt.Text = ItemName + "\t\t" + barcode + "\t\t" + price; // problem lt.Text = ItemName + "& nbsp;" + barcode + "& nbsp;" + price; // &nbsp shows up as text 

but it doesn’t even work. How can I put a space between these lines so that it appears in the list as well

+4
source share
4 answers
 string spaces = Server.HtmlDecode("    "); lt.Text = ItemName + spaces + barcode + spaces + price; // works 
+5
source

I had the same problem and the answers above led me to this, which worked for me.

 string space = " "; space = Server.HtmlDecode(space); line = line.Replace(" ", space); ClassCodeListBox.Items.Add(line); 
+2
source

Try

  lt.Text = string.Format ("{0} \ & nbsp \; {1} \ & nbsp \; {2}", ItemName, barcode, price); 

Replace \\ with & nbsp if you do not see.

or

  lt.Text = string.Format ("{0} {1} {2}", ItemName, barcode, price); 
+1
source

Here are two examples that work well and how to get the current format:

  var SaleItem = new { name = "Super Cereal", barcode = "0000222345", price = 2.55m }; ListItem lt = new ListItem(); string space = " "; lt.Text = String.Concat(SaleItem.name, space, SaleItem.barcode, space, SaleItem.price); lt.Value = SaleItem.barcode; ListItem lt2 = new ListItem(); lt2.Text = string.Copy(String.Format("{0}: {1} {2}", SaleItem.name, SaleItem.barcode, SaleItem.price.ToString("C"))); lt2.Value = SaleItem.barcode; lstMailItems.Items.Add(lt); lstMailItems.Items.Add(lt2); 
0
source

All Articles