ListView. Please, really need help. Thank you.

S

shapper

Hello,

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
 

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

Forum statistics

Threads
473,820
Messages
2,569,723
Members
45,510
Latest member
ThaliaMaxi

Latest Threads

Top