ASP.NET GridView Tutorial
Lesson 149 of 301 · Displaying images in asp.net gridview using imagefield – Part 31 · Database
Displaying images in asp.net gridview using imagefield – Part 31
Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
Link for text version of this video
http://csharp-video-tutorials.blogspot.com/2013/03/displaying-images-in-aspnet-gridview_20.html
In Part 30 of asp.net gridview tutorial we discussed about displaying images in gridview using templatefiled. Please watch Part 30, before proceeding.
ImageFiled is designed for the purpose of displaying images in databound controls like GridView and DetailsView. So, it is better to use ImageField over TemplateField.
We will be modifying the example we discussed in Part 30, to use ImageField instead of TemplateField.
Please note that
1. DataImageUrlField of “ImageField” is set to “Photo” property of the Employee object.
2. To control the width and height of the image in gridview, we are using ControlStyle-Height and ControlStyle-Width properties. Both of them are set to 100 pixels.
3. Use AlternateText property, to specify the text that you want to display, if the image is missing.
4. If you want to have different alternate text for each image displayed, use DataAlternateTextField property.
5. If the image path is null, and if you want to have a different image, then use NullImageUrl property.
6. If you want to display alternate text, when photo path is null, then use NullDisplayText property.