S
shapper
Hello,
I have a ListView defined as follows:
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 MyContextDataContext
Dim tags = From t In database.Tags _
Select t.TagID, t.Text
lv.DataSource = tags
lv.DataBind()
End Sub
Private Sub lv_ItemDeleting(ByVal sender As Object, ByVal e As
ListViewDeleteEventArgs) Handles lv.ItemDeleting
Dim database As New MyContextDataContext
Dim tags = From t In database.Tags _
Where t.TagID = New
Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)
database.Tags.Remove(tags)
End Sub
The ListView displays all records and the ItemDeleting event is fired
but I get an error:
Unable to cast object of type
'System.Data.Linq.DataQuery`1[Undefined.Data.Linq.Tag]' to type
'Undefined.Data.Linq.Tag'
What am I doing wrong?
Thanks,
Miguel
I have a ListView defined as follows:
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 MyContextDataContext
Dim tags = From t In database.Tags _
Select t.TagID, t.Text
lv.DataSource = tags
lv.DataBind()
End Sub
Private Sub lv_ItemDeleting(ByVal sender As Object, ByVal e As
ListViewDeleteEventArgs) Handles lv.ItemDeleting
Dim database As New MyContextDataContext
Dim tags = From t In database.Tags _
Where t.TagID = New
Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)
database.Tags.Remove(tags)
End Sub
The ListView displays all records and the ItemDeleting event is fired
but I get an error:
Unable to cast object of type
'System.Data.Linq.DataQuery`1[Undefined.Data.Linq.Tag]' to type
'Undefined.Data.Linq.Tag'
What am I doing wrong?
Thanks,
Miguel