回复 1# 的帖子
下面是我的一个实例.你可以参考一下:
HTML代码:
<asp:datagrid id="DataGrid1" style="Z-INDEX: 107; LEFT: 136px; POSITION: absolute; TOP: 272px"
runat="server" Width="720px" Height="276px" AutoGenerateColumns="False" PageSize="6" AllowPaging="True"
DataKeyField="ID">
DataKeyField="ID",这个是删除功能中最重要.
代码:
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
= "delete from users where id=" & DataGrid1.DataKeys(CInt(e.Item.ItemIndex)) & ""
mycmd.Connection = mycon
Try
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
Catch ex As Exception
End Try
DataGrid1.EditItemIndex = -1
bind()
End Sub