开发者

Binding a System.Drawing.Image to a Gridview in ASP.Net

I have defined a gridview control with a column of type ImageField and I bind the gridview to a List<MyRecord>.

MyRecord includes a property of type Syste开发者_Go百科m.Drawing.Image, but the image is not rendered in the gridview.

There are numerous articles re binding using the URL field which points to (say) a jpg file... but i have the actual Image, not a file.

Any suggestions?


Create a custom ImageHandler like this article describes:

Image Handling In ASP.NET


That's not how the ImageField works. It expects the URL to the image.

<asp:ImageField DataImageUrlField = "ImageUrl" ...


The Handler.ashx worked... thank you

in the code, i set the ImageUrl = string.Format("~/HandlerGetImage.ashx?id={0}", imageNumber);

This dynamically calls the Handler in which i get the image index by

string v = context.Request.QueryString["id"];

Then, the following returns the image:

   int ix = Convert.ToInt32(v);
   MemoryStream ms = new MemoryStream(Query.imageList[ix]); // imagelist is created elsewhere
   System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);

   context.Response.ContentType = "image/jpeg";

   //saving bitmap image
   returnImage.Save(context.Response.OutputStream,
   System.Drawing.Imaging.ImageFormat.Jpeg);
   returnImage.Dispose();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜