Thursday, January 3, 2013

Bind Image to GridView using Eval

Use below code to add image inside a GridView.

<asp:GridView ID="GridView1" runat="server">
<asp:TemplateField HeaderText="Contact" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left" >

 <HeaderTemplate> Cover Image </HeaderTemplate>
 <asp:Image ID="imgCover" runat="server" AlternateText="Image Cover" ImageUrl='<%# Eval("Cover_Path") %>' /> 
 <HeaderStyle HorizontalAlign="Left">
 <ItemStyle HorizontalAlign="Left">

Remember to use virtual path for Eval("Cover_Path"), not the full path. Something like below.

No comments:
Write comments
Recommended Posts × +