Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > BinaryImage > BinaryImage setting ImageUrl if DataValue is not null fails

Answered BinaryImage setting ImageUrl if DataValue is not null fails

Feed from this thread
  • Timo avatar

    Posted on Jul 8, 2011 (permalink)

    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. :)



    Reply

  • Answer Mira Mira admin's avatar

    Posted on Jul 13, 2011 (permalink)

    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!

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > BinaryImage > BinaryImage setting ImageUrl if DataValue is not null fails