我有一个下拉列表定义为
<asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="ddl1_SelectedIndexChanged" style="width: 107px">
<asp:ListItem Selected="True" Text="Select a value" Value="select">Select a value</asp:ListItem>
<asp:ListItem Value="p1">Image 1</asp:ListItem>
<asp:ListItem Value="p2">Image 2</asp:ListItem>
<asp:ListItem Value="p3">Image 3</asp:ListItem>
</asp:DropDownList>
<div id="img">
<asp:Image ID="image1" runat="server" Width="100"/>
</div>
在更改选择时,事件在代码隐藏中定义为
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
string i = ddl1.SelectedValue;
switch (i)
{
case "p1":
image1.ImageUrl = "img/p1.jpg";
break;
case "p2":
image1.ImageUrl = "img/p2.jpg";
break;
case "p3":
image1.ImageUrl = "img/p3.jpg";
break;
default "select":
image1.ImageUrl = "";
break;
}
}
但是,这似乎并没有选择图像。