我正在使用带有 mysql 数据库的 Web 表单开发一个 ASP.NET Web 应用程序。在我的应用程序中,我已将图像存储在文件夹中,并且该图像的链接存储在数据库中 我想通过从数据库中获取这些链接来显示这些图像 我尝试了以下代码来显示图像
home.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
profile_picture = (string)(Session["link"]); //link has been taken from db
}
home.aspx
<asp:Image runat="server" ID="profile_picture" ImageUrl="Label"></asp:Image>
错误是 =>错误 4 无法将类型“string”隐式转换为“System.Web.UI.WebControls.Image” 怎么解决这个问题? 谢谢。
最佳答案
profile_picture.ImageUrl = (string)(Session["link"]);
这应该有帮助。不确定 ImageUrl 是否是正确的属性,但请查看 System.Web.UI.WebControls.Image(即“profile_picture”的 typeOf),并查看图像链接应设置为哪个属性。
关于mysql - 如何显示数据库获取的链接中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33172864/