This is a migrated thread and some comments may be shown as answers.

Default Value in RadListView

1 Answer 9 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 13 Aug 2020, 04:54 AM

Hi Guys,

I need to generate a default value for a BinaryImage (in a RadListView) when the image source from the database is NULL.

This is the BinaryImage code in RadListView

<asp:PlaceHolder ID="badgeContainer" runat="server"></asp:PlaceHolder>
                </LayoutTemplate>
                <ItemTemplate>
                     
                     <asp:LinkButton ID="lb1" runat="server" CommandName="content" CommandArgument='<%#Eval("bid") %>'>
                    <telerik:RadBinaryImage ID="rbImageBadge"  runat="server" DataValue='<%# IIf(Eval("badge") IsNot DBNull.Value, Eval("badge"), New System.Byte(-1) {})%>' 
                                AutoAdjustImageControlSize="false" Width="120px" Height="120px" ToolTip='<%#Eval("badgetitle", "{0}") %>'
                                AlternateText='<%#Eval("badgetitle", "{0}") %>'    />
                 </asp:LinkButton>
 
''''''''''''''''''''''' etc

 

I have tried everything that I have read but just cannot get it to show a default image.
All help appreciated!

My Handler is 

Imports System.Data.SqlClient
 
Public Class badgeImage : Implements IHttpHandler
 
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
 
        Dim conn As SqlConnection = Nothing
        conn = New SqlConnection(ConfigurationManager.ConnectionStrings("jbdata").ConnectionString)
 
        context.Response.ContentType = "image/png"
 
        Dim id As Integer = Convert.ToInt32(context.Request.QueryString("ID"))
 
        Dim cmdText As String = "select badge from badges where bid=" & id
 
        Dim command As New SqlCommand(cmdText, conn)
        conn.Open()
 
        Dim reader As SqlDataReader = command.ExecuteReader()
 
        reader.Read()
 
        If id > 0 Then
            Dim image As Byte() = DirectCast(reader(0), Byte())
            context.Response.BinaryWrite(image)
        Else
            Dim location As String = System.Web.HttpContext.Current.Server.MapPath("~/badgz/images/default.png")
            System.Web.HttpContext.Current.Response.WriteFile(location)
        End If
 
        reader.Close()
        conn.Close()
 
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class

1 Answer, 1 is accepted

Sort by
0
Jon
Top achievements
Rank 1
answered on 14 Aug 2020, 06:19 AM
Got it.... for anyone else...I needed to put the logic in the itemDataBound event

J

Dim oDataItem As RadListViewDataItem = CType(e.Item, RadListViewDataItem)
If Not oDataItem.DataItem("badge") Is DBNull.Value Then 
               _rbImageBadge.DataValue = CType(DataBinder.Eval(CType(e.Item, RadListViewDataItem).DataItem, "badge"), Byte())
           Else
               _rbImageBadge.DataValue = Nothing
               _rbImageBadge.ImageUrl = "~/badgz/images/default120.png"
           End If
Tags
BinaryImage
Asked by
Jon
Top achievements
Rank 1
Answers by
Jon
Top achievements
Rank 1
Share this question
or