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

2019-08-19 05:21发布

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>

2条回答
Summer. ? 凉城
2楼-- · 2019-08-19 05:59

you can try like this

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

查看更多
Fickle 薄情
3楼-- · 2019-08-19 06:09

'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>
查看更多
登录 后发表回答