NDady:
I'm not 100% sure, but I think it's because your Rows aren't actually
deleted, simply marked for deletion. Let me explain, let's say you have 4
rows, at first it'll look like this:
Grid-Row-0 == DataSet-Row-0
Grid-Row-1 == DataSet-Row-1
Grid-Row-2 == DataSet-Row-2
Grid-Row-3 == DataSet-Row-3
So when you get e.Item.ItemInde x the first time, it'll delete the correct
record in the dataset. However, when you rebind, thinks fall out of synch.
Let's say Row 1 was deleted, it'll now look like:
Grid-Row-0 == DataSet-Row-0
Grid-Row-1 == DataSet-Row-2
Grid-Row-2 == DataSet-Row-3
You see, DataSet-Row-1 still exist, but it isn't bound/displayed. So when
you delete Grid-Row-1, you are getting index "1", and deleting data row "1".
What I would do is place a CommandArgument in the bottom which is the unique
Id of the row and access the value from e.CommandArgume nt.
Karl
"NDady via DotNetMonster.c om" <fo***@nospam.D otNetMonster.co m> wrote in
message news:31******** *************** *******@DotNetM onster.com...
Hi,
I have a datagrid populated from a dataset. On every row in the grid I
have
a delete button. When the user presses on the delete button I remove the
row from the dataset and rebind the datagrid.
The problem is that after a couple of delete the index in the dataset does
not match the index in the grid and the wrong record i deleted from the
dataset. How can I solve this Problem? I am using the following procedure:
Private Sub dg1_ItemCommand (ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
dg1.ItemCommand
If e.CommandName.T oString = "Delete" Then
Dim dset As DataSet
dset = CType(Session(" VideoDset"), DataSet)
dset.Tables(0). Rows(e.Item.Ite mIndex()).Delet e()
dg1.DataSource = dset
Session("videoD set") = dset
dg1.DataBind()
End If
End Sub
Thanks
NDady
--
Message posted via http://www.dotnetmonster.com