2013-02-13 83 views
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())); 
    } 
} 

回答

0

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

尝试是这样的:

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