"Object variable or With block variable not set" error in Edit event

K

Kiyomi

Hello,



I have a datagrid (dgStaffList) with 1 bound column, 2 template columns and
1 Edit column and 1 Delete column. Each template column contains a dropdown
list.



Then I have the following codes, where e.Item.Cells(4) is Delete column :





Sub dgStaffList_ItemCreated(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs)



Select Case e.Item.ItemType

Case ListItemType.Item, ListItemType.AlternatingItem ' ,
ListItemType.EditItem

Dim myTableCell As TableCell

myTableCell = e.Item.Cells(4)

Dim myDeleteButton As LinkButton

myDeleteButton = myTableCell.Controls(0)



myDeleteButton.Attributes.Add("onclick", _

"return confirm('Are you sure you want to delete " +
e.Item.DataItem(1) + "?');")





End Select



End Sub



"Delete" works very well, with confirmation messagebox popping up "Are you
sure you want to delete [staff member's name]."



When I click "Edit", however, I get the error message "Object variable or
With block variable not set" in the line :



myDeleteButton.Attributes.Add("onclick", _

"return confirm('Are you sure you want to delete " +
e.Item.DataItem(1) + "?');")



I tried to replace it with the following line :



myDeleteButton.Attributes.Add("onclick", _

"return confirm('Are you sure you want to delete
this staff member ?');")



Then both "Delete" and "Edit" work, but the staff member's name cannot be
displayed in the messagebox before deleting.



It seems that e.Item.DataItem(1) cannot be recognized in the "Edit" event.
How can I solve this problem ?



I would appreciate very much your advice.



Kiyomi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top