0

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=<%#Eval("Title") %>

1
  • The title of this question is definitely misleading. This is about databinding, not an SQL query per se. Commented Jul 7, 2009 at 7:12

1 Answer 1

2

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() %>
Sign up to request clarification or add additional context in comments.

5 Comments

upon doing so i get the following as the hyperlink localhost:61221/… %> it is not processing Eval
Updated my answer, try the new one please.
i know that method too..i wanted to concatenate literal text and eval method.
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.
yeap I was writing my new answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.