将列表框设为下拉列表

时间:2013-10-30 05:23:54

标签: asp.net

我尝试从下拉列表中为我需要的列表框选择多个选项,但它应该看起来像下拉列表。请告诉我列表框的css将其用作下拉列表。

列表框的css

 .setScroll
        {    
                scrollbar-base-color: WhiteSmoke;
                scrollbar-3dlight-color: Blue;
                scrollbar-arrow-color: Red;
                scrollbar-track-color: WhiteSmoke;
                scrollbar-shadow-color: Blue;
                scrollbar-darkshadow-color: WhiteSmoke;
                scrollbar-face-color: WhiteSmoke;
            }

我想选择多个选项,然后从代码隐藏文件

动态添加此控件

1 个答案:

答案 0 :(得分:0)

标记:

<asp:DropDownList ID="cboItems" runat="server" />

代码背后:

List<ListItem> items = new List<ListItem>();
for (int i = 1; i < 11; i++)
{
    ListItem item = new ListItem();
    item.Text = string.Format("this is a very very long item text corresponding to the  number {0}", i);
    item.Value = i.ToString();
    items.Add(item);
}
cboItems.DataSource = items;
cboItems.DataBind();
// after data bind is complete
cboItems.Attributes["style"] = "width: 100px; max-width: 100px";