Insert whitespace between characters in listbox

穿精又带淫゛_ 提交于 2019-12-01 06:21:54
Jaelebi
string spaces = Server.HtmlDecode("    "); 

lt.Text = ItemName + spaces + barcode + spaces + price; // works

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

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

Try

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

Replace \ \ with &nbsp If you cannot see.

Or

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

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

  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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!