ListItem背景不适用于Chrome

时间:2016-01-16 17:54:47

标签: c# html css asp.net google-chrome

我想在Asp.Net中制作一个图片,但它只是在Firefox中正常工作,并且在IEChrome中无效。我的代码出了什么问题?我在互联网上搜索并尝试了许多代码,但它仍无法正常工作。

<body>
   <form id="form1" runat="server">
      <div>
         <asp:DropDownList ID="drop" runat="server" Width="100px"/>
      </div>
   </form>
</body>

和.cs文件

protected void Page_Load(object sender, EventArgs e)
{
    Loading();
}

string imageUrl;

private void Loading()
{
    List<string> img = new List<string>()
    {
        "Canada",
        "Usa",
        "England",
        "Spain",
        "India"
    };
    drop.DataSource = img;
    drop.DataBind();
    for (int i = 0; i < drop.Items.Count; i++)
    {
        switch (drop.Items[i].Text)
        {
            case "India":
                imageUrl = "Images/India.png";
                break;
            case "Usa":
                imageUrl = "Images/Usa.png";
                break;
            case "England":
                imageUrl = "/Images/England.png";
                break;
            case "Canada":
                imageUrl = "/Images/Canada.png";
                break;
            case "Spain":
                imageUrl = "/Images/Spain.png";
                break;
        }
        drop.EnableViewState = true;
        drop.AppendDataBoundItems = true;
        ListItem item = drop.Items[i];
        item.Attributes["Style"] = "background: url(" + imageUrl + ") no-repeat";
    }
}

0 个答案:

没有答案