Avatar of mossyb123
mossyb123
 asked on

Update ORDER BY in SQL statement with value from dropdown list

I have the connection working with the database but I would like a user to have the ability to view the results in a certain order.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
               
                SelectCommand="SELECT Bids.Name, Bids.Amount, Bids.County, Bids.JobID, Stedents.Student_ID, Stedents.AverageRating FROM Bids INNER JOIN Stedents ON Bids.Student_ID = Stedents.Student_ID WHERE (Bids.JobID = @JobID) Order by ("ddlOrder.Datasource")>
               
                <SelectParameters>
                    <asp:QueryStringParameter Name="JobID" QueryStringField="JobID" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>

All I want is to update the Order by value at the end of the statement when A value is chosen from a dropdown.
 This is the asp for the dropdown.

<asp:DropDownList ID="ddlOrder" runat="server">
         <asp:ListItem Selected = true>Name</asp:ListItem>
         <asp:ListItem>Amount</asp:ListItem>
         <asp:ListItem>Rating</asp:ListItem>
         <asp:ListItem>County</asp:ListItem>
         </asp:DropDownList>

Can someone please help me with this??!!
ASP.NETC#

Avatar of undefined
Last Comment
mossyb123

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
vora_bhaumik

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
krunal_shah

you need to add control parameter to your sqlDataSource like this,


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
               
                SelectCommand="SELECT Bids.Name, Bids.Amount, Bids.County, Bids.JobID, Stedents.Student_ID, Stedents.AverageRating FROM Bids INNER JOIN Stedents ON Bids.Student_ID = Stedents.Student_ID WHERE (Bids.JobID = @JobID) Order by  @Title>
               
                <SelectParameters>
                    <asp:QueryStringParameter Name="JobID" QueryStringField="JobID" Type="Int32" />
<asp:controlparameter name="Title" controlid="ddlOrder" propertyname="SelectedValue"/>

                </SelectParameters>
            </asp:SqlDataSource>

Open in new window

mossyb123

ASKER
I got the following error.

The server tag is not well formed.

Source Error:


Line 86:             <br />
Line 87:            
Line 88:             <asp:SqlDataSource ID="SqlDataSource1" runat="server"
Line 89:                 ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
 
It works if I Order by Name, Amount etc so I know it will work if I can get the value in there!!

SOLUTION
krunal_shah

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
krunal_shah

also i think you ae missing " at the end of your SELECT COMMAND
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
sunithnair

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mossyb123

ASKER
I eneded up using gridview!!