0

在我有一个关于(下拉列表的列之间的特定距离(空格))的问题之前,我收到了如下代码的答案,我的问题是列之间的空格将由'_'填充,当我将其更改为类似" ",它不起作用并且列彼此相邻,我需要列之间的空白,我该怎么做?

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

1 回答 1

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()));
}
于 2013-02-13T12:59:42.153 回答