Can't delete record

Discussion in 'ASP .Net' started by shapper, Dec 4, 2007.

  1. shapper

    shapper Guest

    Hello,

    I have a ListView as defined as follow:

    Private Sub lv_ItemDeleting(ByVal sender As Object, ByVal e As
    ListViewDeleteEventArgs) Handles lv.ItemDeleting
    Dim database As New TestDataContext
    Dim tag As Tag = From t In database.Tags _
    Where t.TagID =
    lv.DataKeys(e.ItemIndex).Value
    database.Tags.Remove(Tag)
    End Sub

    Private Sub lv_Init(ByVal sender As Object, ByVal e As EventArgs)
    Handles lv.Init
    lv.DataKeyNames = New String() {"TagID"}
    lv.ID = "lv"
    lvTags.ItemTemplate = New MyItemTemplate()
    lvTags.LayoutTemplate = New MyLayoutTemplate()
    End Sub

    Private Sub lv_Load(ByVal sender As Object, ByVal e As EventArgs)
    Handles lv.Load
    Dim database As New TestDataContext
    Dim tags = From t In database.Tags _
    Select t.TagID, t.Text
    lv.DataSource = tags
    lv.DataBind()
    End Sub

    My List View displays the records. However the item is not deleted
    when the delete button is fired ...
    I debugged it and the ItemDeleting event is fired!

    What am I doing wrong?

    I also tried with an existing TagId:
    Dim tag As Tag = From t In database.Tags _
    Where t.TagID = New Guid("5f8f46cc-709c-
    dc11-8760-000e35bd65c3")

    But I got the error:
    Unable to cast object of type 'System.Data.Linq.DataQuery`1[Tag]' to
    type 'Tag'.
    Please, could someone tell me what I am doing wrong?

    I don't know what else to try!

    Thanks,
    Miguel
     
    shapper, Dec 4, 2007
    #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. =?Utf-8?B?SnVzdGlu?=

    Retrieving Record Key while creating the record.

    =?Utf-8?B?SnVzdGlu?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    651
    =?Utf-8?B?SnVzdGlu?=
    Oct 5, 2004
  2. André
    Replies:
    0
    Views:
    3,764
    André
    Jun 25, 2006
  3. Rote Rote
    Replies:
    0
    Views:
    409
    Rote Rote
    Oct 1, 2007
  4. MRW
    Replies:
    0
    Views:
    391
  5. -_-
    Replies:
    0
    Views:
    1,399
Loading...

Share This Page