protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-Q02V0BS\AQ;Initial Catalog=upload_file;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select filename from file_table",con);
SqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
Response.Write("<img src="" + Server.MapPath("~/Images/")+ r[0].ToString()+""/>");
}
con.Close();
}
我已将图片名称保存到file_table
且列名为filename
的表格中。单击此按钮时,不会使用当前图像路径生成图像。
答案 0 :(得分:0)
尝试创建图像对象,然后修改其属性。在我的例子中,我创建了一个div,我可以将图像添加到。
demo.aspx:
<div id="imageContainer" runat="server"></div>
demo.aspx.cs
HtmlImage myImage = new HtmlImage();
string myImagePath;
myImagePath = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
myImage.Src = myImagePath;
imageContainer.Controls.Add(myImage);