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

RadBinaryImage cannot display a NULL field

5 Answers 528 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Miao Weibin
Top achievements
Rank 1
Miao Weibin asked on 02 Jul 2009, 07:51 AM
If the image field is NULL, an error will be got : Unable to cast object of type 'System.DBNull' to type 'System.Byte[]' 

5 Answers, 1 is accepted

Sort by
0
BaiH
Top achievements
Rank 1
answered on 02 Jul 2009, 03:56 PM
I'm not very familiar with this control but looking at its documentation it seems that the DataValue property accepts a byte[] (as this is an reference type its value do includes assigning a null value too). However as you may know DBNull is not a null but a completely different type which does not have implicit conversion to byte[] defined. Therefore I do not think this should be supported as in same way you may want to bind the control to a string. ;) Instead you may check if the supplied value is of type DBNull and change it to appropriate empty byte array or null.

--BH
0
Miao Weibin
Top achievements
Rank 1
answered on 03 Jul 2009, 02:48 AM
thanks, BaiH, a NULL field should be cast to null or empty byte[];
0
Bruce Lam
Top achievements
Rank 1
answered on 05 Nov 2009, 10:57 AM
How i can cast object of type 'System.DBNull' to type 'System.Byte[]' “. Please help me . I put RadBinaryImage in ItemTemplate of RadCombobox but in field image of my data have null and image how i can cast. Thanks
0
Miao Weibin
Top achievements
Rank 1
answered on 06 Nov 2009, 03:54 PM
Sorry, maybe CAST is mis-used.

<telerik:RadBinaryImage ID="photoOfUser" Style="float: left;" Width="160px" Height="200px" DataValue='<%#Eval("PHOTO") is DBNull ? null : Eval("PHOTO")%>' AutoAdjustImageControlSize="false" AlternateText="Photo" runat="server"></telerik:RadBinaryImage> 
0
peter
Top achievements
Rank 1
answered on 27 Mar 2013, 04:56 AM
Thank you so much Miao Weibin, it worked for me. Again, so much grateful of you!
Tags
BinaryImage
Asked by
Miao Weibin
Top achievements
Rank 1
Answers by
BaiH
Top achievements
Rank 1
Miao Weibin
Top achievements
Rank 1
Bruce Lam
Top achievements
Rank 1
peter
Top achievements
Rank 1
Share this question
or