SqlDataSource Connection sting + Textbox value

Hello and thanks for reading.

I have a SqlDataSource that I use with my asp:repeater.

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

My Question is: How can I make it select TicketID from my Table Comment that is Equal to The Value in my Textbox "DetailedID"?

<asp:TextBox runat="server" ID="DetailedID" PlaceHolder="ID" ReadOnly="true" />

This is how I think my SelectCommand should look like: SelectCommand="SELECT * FROM [Comment] Where ([TicketID] = DetailedID)"

Thanks for reading and hope you can help me.

Upvotes: 0

Views: 289

Answers (1)

Andrei
Andrei

Reputation: 56726

You can do this specifying ControlParameter for select query. The query should be updated as well to use this parameter:

<asp:SqlDataSource runat="server" ID="SqlDataSource"
                   ConnectionString='<%$ ConnectionStrings:Support_SystemConnectionString %>'
                   SelectCommand="SELECT * FROM [Comment] Where (@DetailedID IS NULL OR [TicketID] = @DetailedID)">
    <SelectParameters>
        <ControlParameter ControlID="DetailedID" PropertyName="Text" Name="DetailedID" />
    </SelectParameters>
</asp:SqlDataSource>

Upvotes: 3

Related Questions