有没有办法在我的下拉条目中获得“表格”外观?

问题描述 投票:0回答:1

使用固定宽度的字体(例如Consolas,Courier等),我试图填充一个有2列(外观)的下拉菜单(AjaxControlToolkit:DropDownList)。我有一个产品名称和一个类别名称(直到运行时我都不知道)。我正在寻找的外观是这样的:

               Chevy Cruz     (gas)
               Prius          (hybrid)
               Tesla Model S  (electic)

我的列表可以有300多个条目,如果我只是将类别附加到产品名称,则菜单更难阅读。

我已经尝试使用字符数组并在每个ListItem的相同索引处复制类别名称,但是当打开下拉列表时,它们之间的空格会消失。我已经查看了ListItem(段落)构造函数,但它并没有解决我对它的理解。我没有看过我可用的Telerik控件,因为它意味着很多编码更改。

我想不出可能有帮助的另一个AjaxControlToolkit控件。

asp.net webforms
1个回答
0
投票

字符串填充可能适合您

var _maxLengthOfProductName = 20; //number of space you need
var _productName = "Product Name";
var _type = "(type)";
var _ProductNameWithType = _productName.PadRight(_maxLengthOfProductName, ' ') + _type; //assign this to the dropdown item
_ProductNameWithType = _ProductNameWithType.Replace(" ", " ");

它会显示出来

Product Name        (type)
© www.soinside.com 2019 - 2024. All rights reserved.