ListView. Please, really need help. Thank you.
am 31.01.2008 22:35:26 von ShapperHello,
I created a Net 3.5 ListView at runtime by implementing ITemplate.
The ListView displays the records and I am able to delete a record.
However, I am not able to insert or update a record.
For example, on the EditItemTemplate I added a custom control named
Form.
This control is nothing more then a groups of TextBoxes, Labels and 2
buttons: Update and Cancel.
When one of the buttons is clicked the custom control Form fires an
Event where I can determine which button was pressed.
My problem is, after knowing that Update was clicked, to update the
record in the database.
I tried everything I could think of.
Could someone please let me know what I should do?
Here is my ListView code:
Private Sub ldsTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles ldsTags.Init
With ldsTags
.ContextTypeName = "CodeDataContext"
.EnableDelete = True
.EnableInsert = True
.EnableUpdate = True
.TableName = "Tags"
.ID = "ldsTags"
End With
End Sub
Private Sub ldsTags_Selecting(ByVal sender As Object, ByVal e As
LinqDataSourceSelectEventArgs) Handles ldsTags.Selecting
Dim database As New CodeDataContext
Dim tags = From t In database.Tags _
Select t.TagID, _
t.Text, _
Active = t.FilesTags.Any Or t.ArticlesTags.Any
e.Result = tags
End Sub
Private Sub lvTags_ItemDeleting(ByVal sender As Object, ByVal e As
ListViewDeleteEventArgs) Handles lvTags.ItemDeleting
Dim database As New CodeDataContext
Dim tag = (From t In database.Tags _
Where t.TagID = New
Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)).Single
database.Tags.DeleteOnSubmit(tag)
database.SubmitChanges()
End Sub
Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Init
With lvTags
.DataKeyNames = New String() {"TagID"}
.DataSourceID = "ldsTags"
.ID = "lvTags"
.InsertItemPosition = InsertItemPosition.FirstItem
End With
With lvTags
.EditItemTemplate = New
TagsTemplate(TemplateType.EditItemTemplate)
.InsertItemTemplate = New
TagsTemplate(TemplateType.InsertItemTemplate)
.ItemTemplate = New TagsTemplate(TemplateType.ItemTemplate)
.LayoutTemplate = New
TagsTemplate(TemplateType.LayoutTemplate)
End With
End Sub
Private Sub lvTags_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Load
lvTags.DataBind()
End Sub
Thank you,
Miguel