hi guys, I have a problem with my datagrid. My form is set up so I have two
textboxes an add button and an editable
datagrid. The datagrid is bound to a datatable which is in my cache.When I
click the add button the contents of the
textboxes are insertedinto the datatabel in teh cache and the datagrid is
bound to it.
However the problem comes when I delete a row from the database and then
add and edit a row. Lets say my datagrid has only
one row, I delete it and then insert a new row. WHen I click on the Edit
button I get the following error
Deleted row information cannot be accessed through the row.
Heres my code for the editable datagrid
Private Sub dgEditEducation_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgEditEducation.ItemCommand
Select Case e.CommandName
Case "Update"
populateEducationQ()
tblEducation = Cache.Get("tblEducation")
Dim dr As DataRow
'find the row which has been clicked on
dr = tblEducation.Rows.Item(e.Item.ItemIndex) '.Find(CType
(E.Item.FindControl("lblEduID2"), Label).Text)
dr.BeginEdit()
dr("institute") = CType(e.Item.FindControl("txtEdEInstitute"), TextBox).Text
dr("location") = CType(e.Item.FindControl("txtEdELocation"), TextBox).Text
dr("eYear") = CType(e.Item.FindControl("ddEdEYar"), DropDownList)
..SelectedItem.Text
dr("major") = CType(e.Item.FindControl("txtEdEMajor"), TextBox).Text
dr("eType") = "q"
dr.EndEdit()
Cache.Insert("tblEducation", tblEducation)
dgEditEducation.EditItemIndex = -1
BindEducationQ()
Case "Edit"
dgEditEducation.EditItemIndex = e.Item.ItemIndex
BindEducationQ()
Dim dr As DataRow
tblEducation = Cache.Get("tblEducation")
dr = tblEducation.Rows(e.Item.ItemIndex)
Dim ddl As DropDownList =
CType(dgEditEducation.Items(dgEditEducation.EditIt emIndex).FindControl
("ddEdEYar"), DropDownList)
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue((dr("eYear "))))
Case "Cancel"
dgEditEducation.EditItemIndex = -1
BindEducationQ()
Case "Delete"
tblEducation = Cache.Get("tblEducation")
Dim dr As DataRow = tblEducation.Rows(e.Item.ItemIndex)
dr.Delete()
Cache.Insert("tblEducation", tblEducation)
BindEducationQ()
dgEducation.ShowFooter = False
dgEducation.EditItemIndex = -1
End Select
End Sub
I really need to know what the problem is as its driving me nuts
--
Message posted via http://www.dotnetmonster.com