【问题标题】:Difficulty in Styling ASP DropDownList [duplicate]设计 ASP DropDownList 的困难 [重复]
【发布时间】:2015-10-28 06:58:04
【问题描述】:

有谁知道如何设置asp 下拉列表的样式?下拉菜单的箭头很难更改,最初是这样的:

有没有人有任何解决方案来修复或设置这个 asp 下拉列表的样式?

这是我的代码:(我无法将其更改为选择下拉列表,因为我的下拉列表选项是根据列表框中的选择动态填充的)

ASP 文件

<asp:DropDownList ID="NewDropDownList" runat="server" Width="136px" 
 OnSelectedIndexChanged="jobRun_SelectedIndexChanged" AutoPostBack="True" >  
</asp:DropDownList>

cs文件

public void BindNewDropDownList()
{
    //Lost to hold the values
    List<DateTime> listCopy = new List<DateTime>();
    DateTime dt;
    string values = String.Join(", ", JOBRUN_CBL.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Text));
    if (values.Contains("Select All"))
    {
        //Loop through each items in listbox and then add it to list
        foreach (ListItem li in ListBox1.Items)
        {
            if (DateTime.TryParse(li.Text, out dt))
            {
                listCopy.Add(dt);
            }
        }
    }
    else
    {
        //Loop through each items in listbox and then add it to list
        foreach (ListItem li in ListBox1.Items)
        {
            //check if item is selected
            if (li.Selected == true)
            {
                //add items to list
                listCopy.Add(DateTime.Parse(li.Text));
            }
        }
    }

    //compare and sort so that the latest date comes on top
    listCopy.Sort((x, y) => y.CompareTo(x));
    //clear the items in dropdownlist
    NewDropDownList.Items.Clear();
    //set the datasource to dropdownlist
    NewDropDownList.DataSource = listCopy;
    //set the dateformatstring in dropdownlist
    NewDropDownList.DataTextFormatString = "{0:dd-MMM-yyyy}";
    //Bind the dropdownlist
    NewDropDownList.DataBind();
}

请帮助我解决这个问题已经有一段时间了,但仍然找不到装饰它的方法。

谢谢。

【问题讨论】:

  • 你想为“下拉”改变什么?你有箭头的图片吗?
  • 嗨@Nic,我正在尝试更改asp下拉列表的背景色和箭头。这只是关于如何更改 ddl 的背​​景色和箭头的一般问题。可以是这样的箭头的任何箭头图像:i.stack.imgur.com/y1T4N.gif。谢谢!
  • 那么我认为重复的链接会帮助你..

标签: javascript c# css asp.net dropdown


【解决方案1】:

您可以轻松设置 DropDownList 的样式

这里有一些对你有帮助的文章

https://wisdmlabs.com/blog/customize-drop-down-list-using-css/

https://css-tricks.com/dropdown-default-styling/

http://www.htmllion.com/default-select-dropdown-style-just-css.html

仅供参考,所有 ASP.NET 控件在浏览器中呈现时都会转换为 HTML 标记,因此您不需要对 DropDownList 进行任何特殊样式设置。您对 SELECT 元素的样式将适用于 DropDownList 。

问候,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 2011-03-08
    • 2020-12-28
    相关资源
    最近更新 更多