【发布时间】:2012-08-25 14:22:58
【问题描述】:
我只想根据 asp.net 网站 ComboBox 中的选定索引更改我的面板背景图像。但是图像没有加载。这是我在 .aspx 页面中的代码
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<div id="divx" style="height: 250px">
<asp:Panel ID="Panel1" runat="server" Height="242px">
</asp:Panel>
</div>
这是背后的代码..
protected void Page_Load(object sender, EventArgs e)
{ }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 1)
{
Panel1.BackImageUrl="C:\\Users\\Laksh\\Documents\\Visual Studio 2010\\WebSites\\WebSite2\\Pic\\Capture.JPG";
}
else if (DropDownList1.SelectedIndex == 2)
{
Panel1.BackImageUrl="C:\\Users\\Laksh\\Documents\\Visual Studio 2010\\WebSites\\WebSite2\\Pic\\erroe.JPG";
}
}
【问题讨论】:
-
你有没有想过使用 Server.MapPath("../Pic/Capture.JPG");获取图片的文件路径名?
-
是的,先生,我试过了……但它给出了一个例外……
'C:/Users/Laksh/Documents/Visual Studio 2010/WebSites/WebSite2/Pic/Capture.JPG' is a physical path, but a virtual path was expected. -
Server.MapPath 将虚拟路径映射到物理位置 - 所以这将导致异常!!见msdn.microsoft.com/de-de/library/…
标签: asp.net drop-down-menu combobox web selectedindexchanged