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

本文关键字:空白 距离 之间 下拉列表 | 更新日期: 2023-09-27 17:58:53

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

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

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

您应该使用&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()));
}