0

別の HTML ページのフォームに応じて、SQL クエリの順序を変更する aspx ページを取得しようとしています。「パーサー エラー メッセージ: サーバー タグの形式が正しくありません」というメッセージが表示され続けます。以下のコードを修正するにはどうすればよいですか?

    <% 
    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 に答える