ImageURL上的c#代码没有显示图像 [英] ImageURL on c# code not showing image
问题描述
我在aspx页面上有图像:
I have image on aspx page as:
<asp:Image ID="imgOrgLogo" runat="server" Width="50px" Height="35px" AlternateText="Image Not Found" />
我在数据库中有它的准备路径,我从数据库中获取图像名称并设置它的路径为:
I have ready path for it in database, and I am fetching image name from database and setting up its path as:
string path = obj.ExecuteScalar(sql);
imgOrgLogo.ImageUrl = "/OrgImages/" + path;
imgOrgLogo.DataBind();
从字符串路径获取图像名称。
from string path I get the image name.
我检查文件夹OrgImages包含指定的图像。
I checked folder OrgImages contains specified image.
但运行此代码后图像无法查看。
But image is not viewing after running this code.
当我从浏览器中检查元素时显示:
When i done inspect element from browser its showing:
<img id="MainContent_imgOrgLogo" src="" alt="Image Not Found"
style="height:35px;width:50px;">
路径未定居。
我的代码有什么问题?
请帮助我。
推荐答案
尝试:
<img id="MainContent_imgOrgLogo" src="" alt="Image Not Found" style="height:35px;width:50px;" runat="server" />
我添加了 runat =server
所以你可以在codebehind中访问< img ID
并设置 src
。
I added runat="server"
so you can access the <img ID
in codebehind and set the src
.
示例: MainContent_imgOrgLogo.Src =(你的IMAGEPATH)
或尝试(因为你是谈论 ddlOrganization_SelectedIndexChanged
):
Or try (since you are talking about a ddlOrganization_SelectedIndexChanged
):
if(!IsPostBack)
{
string path = obj.ExecuteScalar(sql);
imgOrgLogo.ImageUrl = "/OrgImages/" + path;
imgOrgLogo.DataBind();
}
修改:
但是在选择时它应该更改图像。
如果你想实现这一点,你应该把< img
-attribute in UpdatePanel
和 ddlOrganization_SelectedIndexChanged
-event你应该粘贴 .ImageURL
-code。
If you want to achieve that, you should put the <img
-attribute inside a UpdatePanel
and on the ddlOrganization_SelectedIndexChanged
-event you should paste your .ImageURL
-code.
这篇关于ImageURL上的c#代码没有显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!