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

Discussion in 'ASP .Net Datagrid Control' started by Kiyomi, Aug 11, 2006.

  1. Kiyomi

    Kiyomi Guest

    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
     
    Kiyomi, Aug 11, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    581
    San Diego Guy
    Aug 7, 2003
  2. Neo Geshel
    Replies:
    6
    Views:
    4,296
    Cerebrus
    Mar 23, 2006
  3. =?Utf-8?B?TmV3YmllRGV2?=

    Object variable or With Block variable not set error

    =?Utf-8?B?TmV3YmllRGV2?=, Apr 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    584
    =?Utf-8?B?TmV3YmllRGV2?=
    Apr 26, 2006
  4. David C
    Replies:
    0
    Views:
    555
    David C
    Oct 9, 2007
  5. soofimra
    Replies:
    0
    Views:
    460
    soofimra
    May 21, 2008
Loading...

Share This Page