0

Sorry I am new to this, but heres what I'm trying to do.

This is what I currently have

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>

but what Im trying to do is this

SELECT * FROM [Products] WHERE category = categorylabel.Text

I have a column in my database called category, and I want only the data thats category type matches a category in a hidden label (or a session) called categorylabel.Text to do this, the label gets updated with the session. It may be unncessary but I couldnt think of how else to do it.

So how would I go about using my session, to make the SqlDataSource1 only display the data in the Products database that has a category matching that session?

Thanks a lot for the help!

1 Answer 1

1

Try this one:

<asp:SqlDataSource ID="SqlDataSource1" 
                   runat="server" 
                   ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                   SelectCommand="SELECT * FROM [Products] WHERE category=@category">
    <SelectParameters>
        <asp:ControlParameter ControlID="categorylabel" Name="category" PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
Sign up to request clarification or add additional context in comments.

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.