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

BinaryImage setting ImageUrl if DataValue is not null fails

1 Answer 239 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 08 Jul 2011, 07:24 AM
Hello,

I have a database where the user may upload an alternative image for a device.
If the image is not present in the database, the datasource returns a DBNull and the binary image should show the standard image file from the servers image directory.
I used this code which works fine if the image is not present.

<telerik:RadBinaryImage ID="RadBinaryImage1" runat="server"
   DataValue='<%# Eval("Data") is DBNull ? null : Eval("Data")%> '
  
AlternateText=" " AutoAdjustImageControlSize="true" 
   ImageUrl='<%# Eval("Type", "~/Images/Devices/{0}_sml.png") %>'
  
Width="64px" Height="64px" ImageAlign="Middle" ResizeMode="Fit" />

If the database returns the image I get this error message during the page creation:
"Cannot set image Url if DataValue is already set"

If I remove the ImageUrl property, the image of the database is shown properly. So it's surely not a corrupted image file.
I am currently using the following workaround:
<telerik:RadBinaryImage ID="DeviceBinaryImage" runat="server"
    DataValue='<%# Eval("Data") is DBNull ? null : Eval("Data")%> '
   
AlternateText=" " AutoAdjustImageControlSize="true"
    Visible='<%# Eval("Data") is DBNull ? false : true %>'
   
Width="64px" Height="64px" ImageAlign="Middle" ResizeMode="Fit" />
 <asp:Image ID="Image1" runat="server" 
        ImageUrl='<%# Eval("Type", "~/Images/Devices/{0}_sml.png") %>' 
    Visible='<%# Eval("Data") is DBNull ? true : false %>' />

Is it possible to set DataValue and the alternative ImageUrl Property of a single RadBinaryImage?
I would expect the RadBinaryImage to ignore the ImageUrl if DataValue has data.


UPDATE
Forget about the thread.
Simply swapping the order of ImageUrl and DataValue did the trick. :)



1 Answer, 1 is accepted

Sort by
0
Accepted
Mira
Telerik team
answered on 13 Jul 2011, 05:00 PM
Hello Timo,

Generally, it is not recommended to set the DataValue and the ImageUrl properties of the RadBinaryImage at the same time.
In order to implement the desired functionality, I recommend that you handle the ItemDataBound event of the control and set the ImageUrl only if the DataValue is null.

I hope this helps.

Greetings,
Mira
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
BinaryImage
Asked by
Peter
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or