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

Default Value in RadListView

1 Answer 9 Views
This is a migrated thread and some comments may be shown as answers.
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>
                     <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}") %>'    />
''''''''''''''''''''''' 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)
        Dim reader As SqlDataReader = command.ExecuteReader()
        If id > 0 Then
            Dim image As Byte() = DirectCast(reader(0), Byte())
            Dim location As String = System.Web.HttpContext.Current.Server.MapPath("~/badgz/images/default.png")
        End If
    End Sub
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Return False
        End Get
    End Property
End Class

1 Answer, 1 is accepted

Sort by
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


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())
               _rbImageBadge.DataValue = Nothing
               _rbImageBadge.ImageUrl = "~/badgz/images/default120.png"
           End If
Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Share this question