ListView. Please, really need help. Thank you.

Discussion in 'ASP .Net' started by shapper, Jan 31, 2008.

  1. shapper

    shapper Guest

    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
     
    shapper, Jan 31, 2008
    #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. Miguel Dias Moura
    Replies:
    2
    Views:
    351
    Martin
    Jun 22, 2004
  2. Shapper
    Replies:
    4
    Views:
    370
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Jun 15, 2005
  3. shapper
    Replies:
    0
    Views:
    342
    shapper
    Jan 17, 2007
  4. Replies:
    30
    Views:
    1,010
    Arne Vajhøj
    Feb 10, 2008
  5. shapper
    Replies:
    1
    Views:
    2,314
    shapper
    Feb 7, 2008
Loading...

Share This Page