ASP.NET: ListView display Image based on database column being Null or not.

Display images from SQL server database using

I try and got solution is below:

Just typed below code in your aspx page:

<tr style="">
<asp:Literal ID="lblPic" runat="server" />
<a href="?team=<%# TeamNumber() %>&player=<%# Eval("PlayerKey") %>"><asp:Label ID="PlayerLabel"

runat="server" Text='<%# Eval("Player") %>' /></a>
<asp:Label ID="PositionLabel" runat="server" Text='<%# Eval("Position") %>' />

Just type the below code into your code behind.

Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim lblPic As Literal = CType(e.Item.FindControl("lblPic"), Literal)
Dim rowView As System.Data.DataRowView
rowView = CType(e.Item.DataItem, System.Data.DataRowView)

If Convert.IsDbNull(rowView("hasPic") = true then
lblPic.Text = "<img src=\"/Images/sports/never.gif\" alt=\"Picture Available\" CssClass=\"icon right\" />"
lblPic.Text = "<img/> To Display Pic"
End If
End If
End Sub

About the Author