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(By Val source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
dgEditEducation .ItemCommand
Select Case e.CommandName
Case "Update"
populateEducati onQ()
tblEducation = Cache.Get("tblE ducation")
Dim dr As DataRow
'find the row which has been clicked on
dr = tblEducation.Ro ws.Item(e.Item. ItemIndex) '.Find(CType
(E.Item.FindCon trol("lblEduID2 "), Label).Text)
dr.BeginEdit()
dr("institute" ) = CType(e.Item.Fi ndControl("txtE dEInstitute"), TextBox).Text
dr("location") = CType(e.Item.Fi ndControl("txtE dELocation"), TextBox).Text
dr("eYear") = CType(e.Item.Fi ndControl("ddEd EYar"), DropDownList)
..SelectedItem. Text
dr("major") = CType(e.Item.Fi ndControl("txtE dEMajor"), TextBox).Text
dr("eType") = "q"
dr.EndEdit()
Cache.Insert("t blEducation", tblEducation)
dgEditEducation .EditItemIndex = -1
BindEducationQ( )
Case "Edit"
dgEditEducation .EditItemIndex = e.Item.ItemInde x
BindEducationQ( )
Dim dr As DataRow
tblEducation = Cache.Get("tblE ducation")
dr = tblEducation.Ro ws(e.Item.ItemI ndex)
Dim ddl As DropDownList =
CType(dgEditEdu cation.Items(dg EditEducation.E ditItemIndex).F indControl
("ddEdEYar") , DropDownList)
ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByValue((dr(" eYear"))))
Case "Cancel"
dgEditEducation .EditItemIndex = -1
BindEducationQ( )
Case "Delete"
tblEducation = Cache.Get("tblE ducation")
Dim dr As DataRow = tblEducation.Ro ws(e.Item.ItemI ndex)
dr.Delete()
Cache.Insert("t blEducation", tblEducation)
BindEducationQ( )
dgEducation.Sho wFooter = False
dgEducation.Edi tItemIndex = -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