V
VB Programmer
I am trying to use a dropdownlist to fill in the ORDER BY of a
SqlDataSource. Here's part of my HTML...
<asp:SqlDataSource ID="VideoList" runat="server" ConnectionString="<%$
ConnectionStrings:MyMainDatabase %>"
SelectCommand="SELECT aspnet_Users.UserName AS Username,
VideoCategory.VideoCategory, Videos.VideoId AS VideoId,
Videos.VideoDescription, Videos.VideoCaption, Videos.VideoPathUrl,
Videos.IsRacerProfileVideo, Videos.VideoCategoryId, Videos.TimesViewed AS
TimesViewed FROM Videos INNER JOIN VideoCategory ON Videos.VideoCategoryId =
VideoCategory.VideoCategoryId INNER JOIN aspnet_Users ON Videos.UserId =
aspnet_Users.UserId WHERE (Videos.IsRacerProfileVideo = 0) AND
(Videos.VideoCategoryId = @VideoCategoryId) ORDER BY @SortBy">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
Name="VideoCategoryId" PropertyName="SelectedValue" DefaultValue="" />
<asp:ControlParameter ControlID="ddlSort" DefaultValue=""
Name="SortBy" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
The dropdownlist is as follows:
<aspropDownList ID="ddlSort" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True" Value="TimesViewed">Most
Viewed</asp:ListItem>
<asp:ListItem Value="VideoId">Newest</asp:ListItem>
<asp:ListItem Value="Username">Username</asp:ListItem>
</aspropDownList>
Any ideas why this isn't working? Here's the error I'm getting...
The SELECT item identified by the ORDER BY number 1 contains a variable as
part of the expression identifying a column position. Variables are only
allowed when ordering by an expression referencing a column name.
SqlDataSource. Here's part of my HTML...
<asp:SqlDataSource ID="VideoList" runat="server" ConnectionString="<%$
ConnectionStrings:MyMainDatabase %>"
SelectCommand="SELECT aspnet_Users.UserName AS Username,
VideoCategory.VideoCategory, Videos.VideoId AS VideoId,
Videos.VideoDescription, Videos.VideoCaption, Videos.VideoPathUrl,
Videos.IsRacerProfileVideo, Videos.VideoCategoryId, Videos.TimesViewed AS
TimesViewed FROM Videos INNER JOIN VideoCategory ON Videos.VideoCategoryId =
VideoCategory.VideoCategoryId INNER JOIN aspnet_Users ON Videos.UserId =
aspnet_Users.UserId WHERE (Videos.IsRacerProfileVideo = 0) AND
(Videos.VideoCategoryId = @VideoCategoryId) ORDER BY @SortBy">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
Name="VideoCategoryId" PropertyName="SelectedValue" DefaultValue="" />
<asp:ControlParameter ControlID="ddlSort" DefaultValue=""
Name="SortBy" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
The dropdownlist is as follows:
<aspropDownList ID="ddlSort" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True" Value="TimesViewed">Most
Viewed</asp:ListItem>
<asp:ListItem Value="VideoId">Newest</asp:ListItem>
<asp:ListItem Value="Username">Username</asp:ListItem>
</aspropDownList>
Any ideas why this isn't working? Here's the error I'm getting...
The SELECT item identified by the ORDER BY number 1 contains a variable as
part of the expression identifying a column position. Variables are only
allowed when ordering by an expression referencing a column name.