Can't delete record

S

shapper

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
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top