Insert whitespace between characters in listbox

后端 未结 4 1470

I am trying to insert items into a listbox in my asp.net C# application

I concatenate some values and put whitespace in between them but it doesn\'t show up in the l

相关标签:
4条回答
  • 2021-01-14 04:34

    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);
    
    0 讨论(0)
  • 2021-01-14 04:43

    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);
    
    0 讨论(0)
  • 2021-01-14 04:46
    string spaces = Server.HtmlDecode("    "); 
    
    lt.Text = ItemName + spaces + barcode + spaces + price; // works
    
    0 讨论(0)
  • 2021-01-14 04:54

    Try

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

    Replace \ \ with &nbsp If you cannot see.

    Or

    lt.Text = string.Format("{0} {1} {2}",ItemName,barcode,price);
    0 讨论(0)
提交回复
热议问题