RadBinaryImage cannot display a NULL field

6 posts, 0 answers
  1. Miao Weibin
    Miao Weibin avatar
    10 posts
    Member since:
    Jul 2008

    Posted 02 Jul 2009 Link to this post

    If the image field is NULL, an error will be got : Unable to cast object of type 'System.DBNull' to type 'System.Byte[]' 
  2. BaiH
    BaiH avatar
    83 posts
    Member since:
    Aug 2008

    Posted 02 Jul 2009 Link to this post

    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
  3. Miao Weibin
    Miao Weibin avatar
    10 posts
    Member since:
    Jul 2008

    Posted 02 Jul 2009 Link to this post

    thanks, BaiH, a NULL field should be cast to null or empty byte[];
  4. Bruce Lam
    Bruce Lam avatar
    23 posts
    Member since:
    Jun 2009

    Posted 05 Nov 2009 Link to this post

    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
  5. Miao Weibin
    Miao Weibin avatar
    10 posts
    Member since:
    Jul 2008

    Posted 06 Nov 2009 Link to this post

    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> 
  6. peter
    peter avatar
    1 posts
    Member since:
    Jan 2009

    Posted 26 Mar 2013 Link to this post

    Thank you so much Miao Weibin, it worked for me. Again, so much grateful of you!
Back to Top