views:

569

answers:

1

I think it might have been asked before but i was unable to find the right answer, so i am asking here. i have added a data source which is working fine, i wanted a feature where i query the top n entries from the database and add it with a hyperlink. Think of it like Latest News! The markup for the hyperlink inside the ItemTemplate of DataList is this.

 <asp:HyperLink ID="HyperLink1" runat="server" 
                Text='<%# Eval("News_Id") %>' NavigateUrl="~/News.aspx?NewsId=<%#Eval("News_Id") %> " runat="server" /> </asp:HyperLink>

however i get The error as "Error Creating Control, Server tag is not well formed". It reports the error where the quotes are placed.

I know i can use datanavigateurl property but i want to write it in this way. as written in the markup above. How can i?

Upon re writing it to

NavigateUrl='~/Product.aspx?DVDID=<%#Eval("Title") %> '

i get the following as the url

http://localhost:61221/Product.aspx?DVDID=&lt;%#Eval("Title") %>

+2  A: 

try this :

<asp:HyperLink ID="HyperLink1" runat="server"
    Text='<%# Eval("News_Id") %>' 
    NavigateUrl='<%#Eval("News_Id", "~/News.aspx?NewsId={0}") %>' 
    runat="server" /> 
</asp:HyperLink>

<%# Eval() %> must be inside single quotes, otherwise it throws error.

To concatenate string in your binding tag, you can use this :

<%# "~/News.aspx?NewsId=" + Eval("News_Id").ToString() %>
Canavar
upon doing so i get the following as the hyperlinkhttp://localhost:61221/Product.aspx?DVDID=<%#Eval("Title") %>it is not processing Eval
Anirudh Goel
Updated my answer, try the new one please.
Canavar
i know that method too..i wanted to concatenate literal text and eval method.
Anirudh Goel
got it '<%# "~/News.aspx?NewsId=" + Convert.ToString( Eval("id"))%>' this works! Though i know it is primitive way and what you have suggested is the new one and better being datanavigateurl. Thanks nevertheless for helping.
Anirudh Goel
yeap I was writing my new answer :)
Canavar