Add prefix of http:// or https:// with Eval value

巧了我就是萌 提交于 2019-12-25 09:44:45

问题


How can I add the http prefix into my gridview eval value

<asp:HyperLink Target="_blank" 
      NavigateUrl='<%# Eval("SourceURL").ToString().Contains("http:")==true?
                            Eval("SourceURL") :
                            'http://'+ Eval("SourceURL") %>' 
      runat="server" ID="Sorceurl"
      Visible='<%# Eval("SourceURL") == String.Empty ? false : true %>' 
      Text="Source"></asp:HyperLink>

回答1:


'http://' is incorrect - it should be "http://".

You are in C#/ context, so you should be using C# strings.

<asp:HyperLink Target="_blank" 
      NavigateUrl='<%# Eval("SourceURL").ToString().Contains("http:")==true?
                            Eval("SourceURL") :
                            "http://" + Eval("SourceURL") %>' 
      runat="server" ID="Sorceurl"
      Visible='<%# Eval("SourceURL") == String.Empty ? false : true %>' 
      Text="Source"></asp:HyperLink>



回答2:


you can try like this

NavigateUrl='<%# "http://?" + (string)Eval("SourceURL") %>'



来源:https://stackoverflow.com/questions/14120430/add-prefix-of-http-or-https-with-eval-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!