我想在Asp.Net
中制作一个图片,但它只是在Firefox
中正常工作,并且在IE
和Chrome
中无效。我的代码出了什么问题?我在互联网上搜索并尝试了许多代码,但它仍无法正常工作。
<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";
}
}