下拉列表列之间的特定距离(空白)

时间:2013-02-13 12:41:09

标签: c# asp.net

在我有一个关于(下拉列表的列之间的特定距离(空格))的问题之前我收到了我的答案,如下面的代码,我的问题是列之间的空格将填充'_',当我更改对于像“”这样的东西,它不起作用,列彼此相邻,我需要列之间的空格,我该怎么做?

protected void ddlStack_Load(object sender, EventArgs e)
{
    var all = from o in _DataContext.tblDocuments
              orderby o.DocumentNo
              select o;
    int maxs = 0;
    foreach (tblDocuments v in all)
    {
        if (v.DocumentNo.Length > maxs)
            maxs = v.DocumentNo.Length;
    }

    foreach (tblDocuments vv in all)
    {
        string doctitle = vv.DocumentNo;
        for (int i = vv.DocumentNo.Length; i < maxs + 2; i++)
        {
            doctitle += '_';
        }
        doctitle += " | ";
        doctitle +=  vv.DocID;
        ddlStack.Items.Add(new ListItem(doctitle, vv.vendorID.ToString()));
    }
}

1 个答案:

答案 0 :(得分:0)

您应该使用 &nbsp; 而不是常规“”(空格),然后在创建ListBoxItem之前使用 HtmlDecode ...

尝试这样的事情:

foreach (tblDocuments vv in all)
{
    string doctitle = vv.DocumentNo;
    for (int i = vv.DocumentNo.Length; i < maxs + 2; i++)
    {
        doctitle += "&nbsp;";

    }
    doctitle += "&nbsp;|&nbsp;";
    doctitle +=  vv.DocID;

    // Use HtmlDecode to correctly show the spaces
    doctitle = HttpUtility.HtmlDecode(doctitle );

    ddlStack.Items.Add(new ListItem(doctitle, vv.vendorID.ToString()));
}