RadBinaryImage in template - trying to handle NULL values

1 Answer 135 Views
BinaryImage Grid
Hampden Tech
Top achievements
Rank 1
Hampden Tech asked on 10 Aug 2021, 06:05 PM

I have a RadBinaryImage in a RadGrid template column and I'm trying to account for situations where the value is null. In reviewing some of the posts, I saw the following solution.


<telerik:RadBinaryImage runat="server" ID="RadBinaryImage2" DataValue='<%# Eval("vSignature") Is DBNull ? null  Eval("vSignature") %>' AutoAdjustImageControlSize="false" Height="100px" Width="400px" ToolTip="Signature" AlternateText="Signature" />

However, I get a design-time error stating that...

DBNull is a class type and cannot be used as an expression.

I have seen examples of this, but this does not work for me in Visual Studio 2017, Asp.Net 4.6.

Any help on this is greatly appreciated!

1 Answer, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 13 Aug 2021, 10:34 AM

Hello Bob,

You will need to use the "DBNull.Value" Field. The DBNull itself is a Class, see DBNull Class

Also, the Inline if-else condition needs to be corrected and return an empty Byte array if the DataField returns Nothing or DBNull.Value.

VB

DataValue='<%#If(Eval("vSignature") Is DBNull.Value, New Byte() {}, Eval("vSignature")) %>'

 

C#

DataValue='<%# Eval("vSignature") == DBNull.Value ? new byte[] { } : Eval("vSignature") %>'

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Hampden Tech
Top achievements
Rank 1
commented on 13 Aug 2021, 01:17 PM

Okay, thanks Attila, that did the trick!
Tags
BinaryImage Grid
Asked by
Hampden Tech
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or