Question : asp.net< need help in construction of a string with concatenated Eval("") 's

error server error improper string

     <asp:HyperLink ID="HyperLink8"  runat="server" Text='<%# Eval("Address") %>' + ' ' + '<%# Eval("City") %>' + ' ' + '<%# Eval("State") %>'  + ' ' +  '<%# Eval("ZipCode") %>' NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Location").ToString) %>'></asp:HyperLink>

Answer : asp.net< need help in construction of a string with concatenated Eval("") 's

<asp:HyperLink
    ID="HyperLink8"
   runat="server"
    Text='<%# String.Format("{0} {1} {2} {3}", Eval("Address"), Eval("City"), Eval("State"), Eval("ZipCode")) %>'
   NavigateUrl='<%# String.Format("http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q={0}", Server.UrlEncode(String.Format("{0} {1} {2} {3}", Eval("Address"), Eval("City"), Eval("State"), Eval("ZipCode")))) %>'>
</asp:HyperLink>

Just copy the line again otherwise you would have to introduce a variable or new property.

Sometimes I like to introduce a calculated property within the bound object to produce these results:

public string Location
{
   get { return String.Format("{0} {1} {2} {3}", Eval("Address"), Eval("City"), Eval("State"), Eval("ZipCode")); }
}


<asp:HyperLink
    ID="HyperLink8"
   runat="server"
    Text='<%# Eval("Location") %>'
   NavigateUrl='<%# String.Format("http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q={0}", Server.UrlEncode(Eval("Location"))) %>'>
</asp:HyperLink>

DaTribe
Random Solutions  
 
programming4us programming4us