In my .aspx code i have the following element
<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# Eval("ProductImage") %>' />
The value returned for this is a image URl from a content delivery network with a sample url like 'http://cdn.xyz.com'
I want to convert the url to 'https://cdn.xyz.com'
I tried to do ImageUrl='<%# Eval("ProductImage").Replace("http","https") %>'
which doesnt seem to work. Any ideas?
You can handle it like:
<%# ((string)Eval("ProductImage")).Replace("http", "https") %>
And if your string can be Null
<%# ((string)Eval("ProductImage") ?? string.Empty).Replace("http", "https") %>
And it will be:
<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# ((string)Eval("ProductImage") ?? string.Empty).Replace("http", "https") %>'
OR if you are sure your string will not be Null
in any case.
<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# ((string)Eval("ProductImage")).Replace("http", "https") %>'
Try this, you might have to first convert to String
for Replace
to work:
<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# Eval("ProductImage").ToString().Replace("http","https") %>'
Eval
returns object
and Replace
wouldn't work on object
. You need to Cast/Convert
the returned object
into String
first and then use the Replace
method on that String
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With