我只想根據asp.net網站中ComboBox中選定的索引更改我的面板背景圖像。但圖像不加載。這是我在.aspx頁面中如何將asp.net中的圖片更改爲組合框選定的索引更改
<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」);獲取圖像的文件路徑名? – KingPancake
是的,我試過先生..但它給了一個例外... 'C:/用戶/ Laksh /文件/ Visual Studio 2010/WebSites/WebSite2/Pic/Capture.JPG'是一個物理路徑,但一個虛擬路徑預計將會出現。' – tharindlaksh
什麼是例外? – KingPancake