display image in gridview

Posted by Klbaiju under ASP.NET on 1/15/2011 | Points: 10 | Views : 24852 | Status : [Member] | Replies : 5
Hi,
I want to display in image in gridview .

this is gridview

<asp:GridView ID="gvDetails" runat="server" AllowPaging="True" >

<Columns>
<asp:TemplateField HeaderText="Cover">
<ItemTemplate>

<asp:Image Height="200px" Width="150px" ID="imgSaved" runat="server" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "cover") %>'
AlternateText='<%#DataBinder.Eval(Container.DataItem,"BookName") %>' />
</ItemTemplate>

</asp:TemplateField>
<asp:BoundField DataField="BookID" HeaderText="Book ID" SortExpression="BookID" />
here is the problem

<asp:Image Height="200px" Width="150px" ID="imgSaved" runat="server" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "cover") %>'
AlternateText='<%#DataBinder.Eval(Container.DataItem,"BookName") %>' />


Regards

Baiju

</Columns>
</asp:GridView>


i want to display cover in gridview. datattype of cover is varbinary(Max).
my image is stored in database as varbinary.
but image is not display.all other fields are displaying fine.
this is the code


DataSet ds = new DataSet();
SqlDataAdapter adp;
adp = new SqlDataAdapter("SELECT * FROM BooksDetails", conn);
ds.Clear();
adp.Fill(ds, "BooksDetails");
gvDetails.DataSource = ds;
gvDetails.DataBind();




Responses

Posted by: Karthikanbarasan on: 1/15/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Its always better to stored the image int he virtual directory instead in DB, since the size of the db gets huge and its not the best standard to work on. Check this link.. it has the samples for your requirements

http://www.codeproject.com/KB/aspnet/GridImage.aspx

Thanks
Karthik
www.f5Debug.net

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 1/15/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Klbaiju,

This article has solution to your question http://www.dotnetfunda.com/articles/article1084-saving-images-into-the-database-in-aspnet-and-displaying-to-the-gridview-.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 1/22/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
hi Klbaiju

simply add in a gridview Image field and in set ur imrurl column name in DataImageUrl Field
then ur iamge display in gridview

Thanks & Regard's
Prabhakar

Best Regard's
Prabhakar

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 1/24/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

I was facing same problem.
so to resolve this problem you need to add .ashx (Handler file) into your project and retrieve images from that file.
just read any tutor how to use that file then you can do this easily.



Happy Programming!!
Rohi

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 1/24/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi...

for Code sample demo try this link will guide you...

http://csharpdotnetfreak.blogspot.com/2009/07/display-images-gridview-from-database.html

LP MER

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response