Binding Image URL with RadImageButton

477 Views Asked by At

I asked on Telerik's site, but there is apparently not enough traffic there to generate answers.

I am trying to convert an asp ImageButton to a RadImageButton because there are some useful features that would make my life a bit easier. However, the binding for the image URL won't work - at least the way I am doing it.

So this works (both are in the same ListView):

<asp:ImageButton ID="im" runat="server" ImageUrl='<%# Eval("ImgUrl") %>' />

But this:

<telerik:RadImageButton runat="server" ID="itemImageButton" '>
    <Image Url='<%# Eval("ImgUrl") %>' />
</telerik:RadImageButton>

gives me an error something like Telerik.Web.UI.ButtonBase.ButtonImage does not have a DataBinding event.

If someone could point me in the right direction to get this done with the RadImageButton control (if possible), I would appreciate it.

1

There are 1 best solutions below

1
On BEST ANSWER

I was recently facing exactly the same issue. Apparently child objects/properties in some controls are not DataBound-able.

You have to do the binding for the image URL inside the telerik:RadImageButton tag itself, so instead of using <Image Url="" /> section, place it in the Image-Url attribute:

<telerik:RadImageButton runat="server" ID="itemImageButton" Image-Url='<%# Eval("ImgUrl").ToString() %>'>
</telerik:RadImageButton>

You can ommit .ToString() part though.

One more "issue" that I've got when switching from asp:ImageButton to telerik:RadImageButton was the necessity to set the width and height explicitly. Without it, it didn't work ouf of the box. Image (icon) was malformed, even though it was like 24x24 sized. I ended up setting width="" and height="" attributes, but adding CssClass and using styles should work too.