Friday 24 May 2013

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


Add prefix of http:// or https:// with 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>


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>



you can try like this
NavigateUrl='<%# "http://?" + (string)Eval("SourceURL") %>'

No comments:

Post a Comment