Link to home
Start Free TrialLog in
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??!!
ASKER CERTIFIED SOLUTION
Avatar of vora_bhaumik
vora_bhaumik
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of krunal_shah
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

Avatar of 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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also i think you ae missing " at the end of your SELECT COMMAND
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I eneded up using gridview!!