1
<asp:SqlDataSource ID="itemsforsale" runat="server"
     ConnectionString="<%$ ConnectionStrings:ElmtreeConnection  %>"
     SelectCommand="SELECT * FROM Products WHERE Products.CategoryId = @CategoryId">

     <SelectParameters>
         <asp:QueryStringParameter Name="CategoryId" 
              QueryStringField="CategoryId" Type="Int32" />
     </SelectParameters>
</asp:SqlDataSource>

<asp:HyperLink ID="hyperlink" runat="server" 
     NavigateUrl='<%# "ItemsForSale.aspx?CategoryId"+Eval("CategoryId") %>' 
     Text="Beauty"></asp:HyperLink>

This is my markup. I'm not getting any errors when loading the page, however the link is not working. Can anyone give me any insight as to why?

2 Answers 2

3

An equal sign is missing in the URL:

NavigateUrl='<%# "ItemsForSale.aspx?CategoryId=" + Eval("CategoryId") %>'

If the HyperLink is not in a databound control, you must call its DataBind method (or the DataBind method of the Page itself) in Page_Load to make sure that its databinding expression is evaluated:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        hyperlink.DataBind();
        ...
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, however this still hasn't solved the problem.
I added another suggestion in my answer.
Thanks, this worked! Been at this for days, you're a life saver.
1

You're essentially creating a Url to the address ItemsForSale.aspx. Prefix your URL with ~/ to have it recognized as a route relative to your base url.

3 Comments

I tried that, and it's still not working. When I click the hyperlink, it's dead. It's not directing me to any page.
Have you confirmed that you can navigate to that page at all?
Yes, can definitely navigate to the page.

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.