Hyperlink + Eval + navigateURL

0

I would like to create a link in the row of the listview to navigate to a url when clicked. The "city" field has to complete the url so that the targeting is done correctly.

<%#Eval("cidade")%>

Example: Let's say I want the user to be directed to the wikipedia to view the information of the clicked city and so on, like this: link "city"

    
asked by anonymous 21.09.2016 / 17:50

1 answer

0

In NavigateUrl of the component # that is within a ItemTemplate of the component em> ListView do: / p>

NavigateUrl='<%#string.Format("https://pt.wikipedia.org/wiki/{0}", Eval("Cidade"))%>'>     

Full Code:

<form id="form1" runat="server">
    <div>
        <asp:ListView ID="ListView1" runat="server">
            <ItemTemplate>
                <asp:HyperLink 
                    ID="HyperLink1" 
                    runat="server" 
                    Text ='<%#Eval("Cidade") %>'
                    NavigateUrl='<%#string.Format("https://pt.wikipedia.org/wiki/{0}", Eval("Cidade"))%>'>                    
                </asp:HyperLink>
            </ItemTemplate>
        </asp:ListView>
    </div>
</form>

In the latest version you can do this too:

NavigateUrl='<%#$"https://pt.wikipedia.org/wiki/{Eval("cidade")}"%>'>

This feature calls: C # 6 - String Interpolation

    
21.09.2016 / 18:37