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:Connecti onString %>"
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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Connecti
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:
<asp:ListItem>Rating</asp:
<asp:ListItem>County</asp:
</asp:DropDownList>
Can someone please help me with this??!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:Connecti onString %>"
It works if I Order by Name, Amount etc so I know it will work if I can get the value in there!!
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:Connecti
It works if I Order by Name, Amount etc so I know it will work if I can get the value in there!!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also i think you ae missing " at the end of your SELECT COMMAND
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I eneded up using gridview!!
Open in new window