0

I have been searching for this for quite a while and couldn't find a solution...

I have my aspx file and in it a asp:SqlDataSource, where I want to get values which are equal to the Request.QueryString["key"]. I have defined a parameter for it but I can't find the right syntax to set the value.

Currently it is looking like this:

<SelectParameters>
    <asp:Parameter Name="courseID" DefaultValue="<%= Request.QueryString["course_name"]
</SelectParameters>

where I always get the error, it is not well formed. What is the correct syntax, and is there an article how you use this <%.. %> commands?

1
  • Can you show an example of your code? Commented Dec 8, 2010 at 1:21

2 Answers 2

4

There's an MSDN page that goes over what each tag is and what it does. Probably using <%...%> is not correct, as that's just a code tag. You want <%=...%> or <%:...%> which actually write values to the page.

But! Actually, if I'm reading what your problem is correctly, you want neither of those. For a SqlDataSource to pull in a query string value, you want to add a <SelectParameters> tag to the datasource, then add a <QueryStringParameter> to that.

Edit:

Yep, looking at the edit you just made, you definitely want a QueryStringParameter.

Sign up to request clarification or add additional context in comments.

Comments

2

You can't use <%= within high-level asp controls. That construct writes directly to the output buffer, whereas the controls need to be processed first. In other words, rather than processing your <%= before expanding the control, it must first expand the control before it can process your <%=. They are at different levels of abstraction.

To do what you want to accomplish, rather than a plain <asp:Parameter> use an <asp:QueryStringParameter>. This will allow you to set the key you want to use from the query string.

Comments

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.