我有一个图像控件。单击修改按钮后,图像未加载到图像控件。图像已成功保存,但无法加载。图像保存在文件夹中。我写了以下代码。
string subs = dTable.Rows[0]["Logo"].ToString();
foreach (var file in filePaths)
{
string sFileName = Path.GetFileName(file);
if (sFileName == subs)
{
img.ImageUrl = file;
}
}
答案 0 :(得分:2)
尝试在容器中添加img
控件,例如样本面板:
if (sFileName == subs)
{
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = file;
pnl.Controls.Add(img);
}
在你的asp.net页面中:
<asp:Panel ID="pnl" runat="server"></asp:Panel>
答案 1 :(得分:0)
SqlConnection Ocon = new SqlConnection(WebConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString);
string sqlQyery = "Select *from StoreFile where ItemId=1";
try
{
SqlDataAdapter da = new SqlDataAdapter(sqlQyery, Ocon);
DataTable dtimage = new DataTable();
da.Fill(dtimage);
if (dtimage.Rows.Count > 0)
{
foreach (DataRow dr in dtimage.Rows)
{
Image img1 = new Image();
// Images Path
img1.ImageUrl = "~/MyFiles/" + dr["ItemId"].ToString() + "/" +
dr["FileName"].ToString();
pnlImages.Controls.Add(img1);
}
}
}
catch (Exception ex)
{ }