2017-01-12 24 views
0

字符串以我的.aspx代码我有以下元件替换的DataBinder.Eval

<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# Eval("ProductImage") %>'            /> 

该返回的值是从内容传递网络与样品URL一个图像URL等'http://cdn.xyz.com'

我想将网址转换为'https://cdn.xyz.com'

我试图做ImageUrl='<%# Eval("ProductImage").Replace("http","https") %>'这似乎并不奏效。有任何想法吗?

+0

您的'ProductImage'从哪里来?你不想在那里改变它吗?在'.cs'(代码后面)? –

+0

@teovankot,我没有访问后面的代码。它坐在dll – ScottyDoesKnow

+0

不确定,但你有没有尝试过这样的:'((字符串)评估(“ProductImage”))替换(“http”,“https”)'? –

回答

4

您可以处理它想:

<%# ((string)Eval("ProductImage")).Replace("http", "https") %> 

如果你的字符串可以是Null

<%# ((string)Eval("ProductImage") ?? string.Empty).Replace("http", "https") %> 

这将是:

<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# ((string)Eval("ProductImage") ?? string.Empty).Replace("http", "https") %>' 

,或者如果您确信您的字符串在任何情况下都不会是Null

<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# ((string)Eval("ProductImage")).Replace("http", "https") %>' 
2

试试这个,你可能必须先转换为StringReplace工作:

<asp:Image ID="GalleryImage" runat="server" ImageUrl='<%# Eval("ProductImage").ToString().Replace("http","https") %>' 

Eval回报objectReplace不会对object工作。您需要将Cast/Convert返回的object转换为String,然后在该String上使用Replace方法。