0

我一直在尝试通过依赖另一个 html 页面的表单来获取一个 aspx 页面来更改 sql 查询的顺序。它一直给我一个“解析器错误消息:服务器标签格式不正确。” 如何修复下面的代码?

    <% 
    Dim SortingOrder = Request.QueryString("sortorder")
%>
<form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
        <Columns>
            <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
            <asp:BoundField DataField="Summary" HeaderText="Summary" SortExpression="Summary" />
            <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
            <asp:BoundField DataField="GenreId" HeaderText="GenreId" SortExpression="GenreId" />
            <asp:CheckBoxField DataField="Authorized" HeaderText="Authorized" SortExpression="Authorized" />
            <asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime" SortExpression="CreateDateTime" />
            <asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime" SortExpression="UpdateDateTime" />
        </Columns>
    </asp:GridView>
    <asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:PLANETWROX.MDFConnectionString1 %>" deletecommand="DELETE FROM [Review] WHERE [Id] = @Id" insertcommand="INSERT INTO [Review] ([Title], [Summary], [Body], [GenreId], [Authorized], [CreateDateTime], [UpdateDateTime]) VALUES (@Title, @Summary, @Body, @GenreId, @Authorized, @CreateDateTime, @UpdateDateTime)" providername="<%$ ConnectionStrings:PLANETWROX.MDFConnectionString1.ProviderName %>" selectcommand="SELECT [Id], [Title], [Summary], [Body], [GenreId], [Authorized], [CreateDateTime], [UpdateDateTime] FROM [Review] ORDER BY Request.QueryString("sortorder")" updatecommand="UPDATE [Review] SET [Title] = @Title, [Summary] = @Summary, [Body] = @Body, [GenreId] = @GenreId, [Authorized] = @Authorized, [CreateDateTime] = @CreateDateTime, [UpdateDateTime] = @UpdateDateTime WHERE [Id] = @Id">
        <DeleteParameters>
            <asp:Parameter Name="Id" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Summary" Type="String" />
            <asp:Parameter Name="Body" Type="String" />
            <asp:Parameter Name="GenreId" Type="Int32" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="CreateDateTime" Type="DateTime" />
            <asp:Parameter Name="UpdateDateTime" Type="DateTime" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Summary" Type="String" />
            <asp:Parameter Name="Body" Type="String" />
            <asp:Parameter Name="GenreId" Type="Int32" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="CreateDateTime" Type="DateTime" />
            <asp:Parameter Name="UpdateDateTime" Type="DateTime" />
            <asp:Parameter Name="Id" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
        ShowSelectButton="True" ButtonType="Button"></asp:CommandField>
    <asp:Database.Query(Select * From Review [Order By<% Response.Write(Request.QueryString("sortorder"))%>])></asp:Database.Query>
    </form>
4

2 回答 2

3

你的问题在这里:

selectcommand="SELECT [Id], [Title], [Summary], [Body], [GenreId], [Authorized], [CreateDateTime], [UpdateDateTime] FROM [Review] ORDER BY Request.QueryString("sortorder")"

中的双引号 Request.QueryString("sortorder")"过早关闭标签。而且您不能直接使用查询字符串。

应该是这样的:

SelectCommand="Select EmployeeID, LastName From Employees where EmployeeID = @empId">
    <SelectParameters>
      <asp:QueryStringParameter     Name="empId" QueryStringField="empId" />
    </SelectParameters>

取自此页面:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.querystringparameter.querystringfield.aspx

于 2013-07-17T22:15:45.270 回答
0
<% should be <%= in order by

Explained already here: script tags in html

and remove Response.Write from that statement.

于 2013-07-17T22:16:38.830 回答