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">
<Columns>
<asp:TemplateField HeaderText="Contact" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left" >

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

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

No comments:
Write comments
Recommended Posts × +