0

Following is my code.

protected void Button3_Click(object sender, EventArgs e)
    {
        var newLsit = new List<string>();
        newLsit.Add("1 1");
        newLsit.Add("1  1");
        newLsit.Add("1   1");
        this.DropDownList1.DataSource = newLsit;
        this.DropDownList1.DataBind();

    }

When dropdown list displays the values all the values are coming as "1 1" "1 1" "1 1"

How to display extra spaces as well and avoid this trimming?

Chaitany Ram
  • 141
  • 2
  • 5
  • 16

2 Answers2

1

Use &nbsp; instead of " ". Your code should look like this.

protected void Button3_Click(object sender, EventArgs e)
    {
        var newLsit = new List<string>();
        newLsit.Add("1&nbsp;1");
        newLsit.Add("1&nbsp;&nbsp;1");
        newLsit.Add("1&nbsp;&nbsp;&nbsp;1");
        this.DropDownList1.DataSource = newLsit;
        this.DropDownList1.DataBind();

    }
Jonas T
  • 2,989
  • 4
  • 32
  • 43
1

you can try this

int num=1;
        newLsit.add("1"+String.format("%"+num+"s","1"));
        num=2;
        newLsit.add("1"+String.format("%"+num+"s","1"));
        num=3;
        newLsit.add("1"+String.format("%"+num+"s","1"));
Abrial
  • 421
  • 1
  • 5
  • 20