GridView,删除的是索引值而不是主键!
1.前台代码:
<div>
<asp:GridView ID="GVZhaoPin" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ZhaoPinID" OnLoad="GVZhaoPin_Load" OnRowCancelingEdit="GVZhaoPin_RowCancelingEdit" OnRowCommand="GVZhaoPin_RowCommand" OnRowDataBound="GVZhaoPin_RowDataBound" OnRowDeleting="GVZhaoPin_RowDeleting" OnRowEditing="GVZhaoPin_RowEditing">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="cbSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
<asp:BoundField DataField="ZhaoPinID" />
<asp:BoundField DataField="ZhaoPinTitle" HeaderText="标题" />
<asp:BoundField DataField="ZhaoPinTime" HeaderText="发布时间">
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="发布人" />
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField>