ASP.net dropdownlist在自动显示时修剪额外的空间

ASP.net dropdownlist在自动显示时修剪额外的空间,asp.net,drop-down-menu,texttrimming,Asp.net,Drop Down Menu,Texttrimming,下面是我的代码 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 = newL

下面是我的代码

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"
protectedvoid按钮3\u单击(对象发送者,事件参数e)
{
var newLsit=新列表();
新增(1)条;
新增(1)条;
新增(1)条;
this.DropDownList1.DataSource=newLsit;
this.DropDownList1.DataBind();
}
当下拉列表显示值时,所有值都显示为“1 1”“1 1”

如何显示额外的空格并避免此修剪?

使用
而不是
。您的代码应该如下所示

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();

    }
protectedvoid按钮3\u单击(对象发送者,事件参数e)
{
var newLsit=新列表();
新增(1)条;
新增(1)条;
新增(1)条;
this.DropDownList1.DataSource=newLsit;
this.DropDownList1.DataBind();
}
您可以试试这个

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"));

谢谢,我刚刚写了一个示例,但是我的原始代码包含一个实体列表。那么,在渲染之前,我是否需要编写一些通用代码来加密实体列表?您能否提供更多详细信息?我可以通过您的代码看到lsit中的字符