Saroop Trivedi
Saroop Trivedi

Reputation: 2275

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

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>

Upvotes: 0

Views: 1537

Answers (2)

MahaSwetha
MahaSwetha

Reputation: 1066

you can try like this

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

Upvotes: 0

Oded
Oded

Reputation: 499172

'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>

Upvotes: 1

Related Questions