我正在尝试在网格视图中启用删除。当您运行此代码并按下删除按钮时,您会收到错误必须声明标量变量“@Content”。
代码
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Content" HeaderText="Content" SortExpression="Content" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [ImportantNews]"
DeleteCommand="DELETE FROM [ImportantNews] WHERE [Content] = @Content AND [Title] = @Title">
<DeleteParameters>
<asp:Parameter Name="Title" Type="string"/>
<asp:Parameter Name="Content" Type="string"/>
</DeleteParameters>
</asp:SqlDataSource>
请注意我使用的是 Asp.net 2.0