郭工:
A页面的Gridview显示数据列表,由列ID调用B页面,B页面的FpSpread的单元格用下列代码显示图片:
//链接数据源,取得数据集
if (Ds.Tables[0].Rows.Count > 0)
{
FpSpreadFile.DataSource = Ds.Tables[0];
FpSpreadFile.DataBind();
FpSpreadFile.Sheets[0].Columns[8].Width = 200;
for (int I = 0; I < Ds.Tables[0].Rows.Count; I++)
{
byte[] photo = new byte[0];
photo = (byte[])Ds.Tables[0].Rows[I][8];
TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
Bitmap bm = (Bitmap)tc.ConvertFrom(photo);
string FileName = "~/Image/Image" + (I + 1).ToString() + ".jpg";
if(File.Exists (FileName ))
{
try
{
File.Delete(FileName);
}
catch (Exception ex)
{
throw ex;
}
}
bm.Save(Server.MapPath(FileName));
FpSpreadFile.ActiveSheetView.Cells[I, 8].Value = null;
FarPoint.Web.Spread.ImageCellType ict = new FarPoint.Web.Spread.ImageCellType();
FpSpreadFile.ActiveSheetView.Cells[I, 8].CellType = ict;
ict.TextOnRight = false;
ict.ImageAlign = ImageAlign.AbsMiddle;
//ict.ImageUrl = "~/Image/Image" + (I + 1).ToString() + ".jpg";
ict.ImageUrl = FileName;
ict.CssClass = "test";
}
}
FpSpreadFile.SaveChanges();
Ds.Dispose();
Da.Dispose();
第一次显示图片正确,关闭B页面,重新选择另一ID再打开B页面,显示的图片还是上一次ID的图片,如何设置?保证图片更新?
|
|