删除gridview中的链接,删除所有行
本文关键字:删除 链接 gridview | 更新日期: 2023-09-27 18:15:04
我正面临着一个问题,我的gridview作为删除链接正在删除所有的行,我想删除一个接一个。我已经记录了我的屏幕,可以解释更多关于我的问题
https://www.youtube.com/watch?v=VAh0A-UOafU&特性= youtu.be
<asp:GridView ID="FavoritGRDSHOW" runat="server" AllowPaging="True"
DataKeyNames="FavID" DataSourceID="FavoriteGRDView"
PageSize="6" Width="600px">
<Columns>
<asp:CommandField ShowDeleteButton="True" ButtonType="Image"
DeleteImageUrl="~/iconsimg/Delete2.png" />
<asp:BoundField DataField="FavID" HeaderText="FavID"
InsertVisible="False" ReadOnly="True" SortExpression="FavID" />
<asp:BoundField DataField="AdsID" HeaderText="AdsID"
SortExpression="AdsID" />
<asp:BoundField DataField="UID" HeaderText="UID" SortExpression="UID" />
<asp:BoundField DataField="AdsTit" HeaderText="AdsTit"
SortExpression="AdsTit" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="FavoriteGRDView" runat="server"
ConnectionString="<%$ ConnectionStrings:BeravaConnectionString %>"
SelectCommand="SELECT [FavID], [AdsID], [UID], [AdsTit] FROM [favourite]
WHERE ([UID] = @UID)"
OldValuesParameterFormatString="original_{0}"
DeleteCommand="DELETE FROM [favourite] WHERE [FavID] = FavID" >
<SelectParameters>
<asp:SessionParameter Name="UID" SessionField="UsrNme" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
您的delete语句:
DELETE FROM [favourite] WHERE [FavID] = FavID
等价于这个,因为每条记录都将匹配它自己的字段:
DELETE FROM [favourite] // deletes all rows in the table
您需要指定要删除的ID并将其作为参数传递:
<asp:SqlDataSource ID="FavoriteGRDView" runat="server" ConnectionString="<%$ ConnectionStrings:BeravaConnectionString %>"
DeleteCommand="DELETE FROM [favourite] WHERE [FavID] = @FavID">
<DeleteParameters>
<asp:Parameter Name="FavID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
use this:
<asp:SqlDataSource ID="FavoriteGRDView" runat="server" ConnectionString="<%$ ConnectionStrings:BeravaConnectionString %>"
DeleteCommand="DELETE FROM [favourite] WHERE [FavID] = @FavID">
<DeleteParameters>
<asp:ControlParameter ControlID="FavoritGRDSHOW" PropertyName="SelectedValue" Name="FavID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>