Hi all
I need help in retriving images from access database and it should show up in gridView using VB.Net
Can anyone help please?
Thanks in advance
Hi all
I need help in retriving images from access database and it should show up in gridView using VB.Net
Can anyone help please?
Thanks in advance
Look up GridView ItemDataBound Event handler. It allows you to add code to your databind control at runtime. Including code to display an imagine in a row of the Data Control.
Normally, you would use a FileHandler to do this. But that will cause an additional databasecall for each and every image you show.
http://www.mikesdotnetting.com/Article/123/Storing-Files-and-Images-in-Access-with-ASP.NET
However, there’s a trick you can use to show all the images with just 1 database call. It involves convert the imagebytes into a Base64 string. Assuming you store the image in a field names imagedata, and the image type (MIME type) in a field called imagetype, you can create a Template field like:
<asp:TemplateField HeaderText="image">
<ItemTemplate>
<asp:Image ID="Image1"
runat="server"
ImageUrl='<%# string.format("data:{0};base64,{1}", Eval("imagetype"), Convert.ToBase64String(Eval("imagedata"))) %>'
EnableViewState="false" />
</ItemTemplate>
</asp:TemplateField>
Note I disabled the ViewState of the Image, because it will grow very big if you have many images…
Thanks verschha on ur replay.
what do u mean by MIME type?
where is that in access or gridview?
i stored the image path (the filed data type is text) in access db. how can i retrive it/them?
in your example what should i store in the db e.g the path of the image or what?
thanks in advance
You said that you stored the image in the database, not the image path! In that case, it is very easy using an imagefield (scroll down for an example…)