asp.netlistviewitemtemplateedititemtemplate

How to switch back to EditTemplate after an Update to ItemTemplate in a ListView


It have a ListView with LayoutTemplate, ItemTemplate and EditTemplate. The List view only ever shows one item. The ItemTemplate as an EditButton with CommandName = 'Edit' which when clicked triggers...

Protected Sub ListView1_ItemEditing(ByVal sender As Object, ByVal e As ListViewEditEventArgs) Handles ListView1.ItemEditing

    ListView1.EditIndex = e.NewEditIndex

    'Create SQL and load result in datatable and bind to listview 
    LoadData(Session("SID"))

End Sub

The EditTemplate has an UpdateButton with CommandName 'Update' which when clicked triggers...

Protected Sub ListView1_Command(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles ListView1.ItemCommand

    If e.CommandName = "Update" Then

        'Use StringBuilder to build up an UPDATE TSql script
        SqlStr = sb.ToString
        'Execute Update
        ExecuteSQLScript(SqlStr)

    End If

The above works great. My question is how do I now get back to ItemTemplate View. I know that I must use the ItemUpdating method similar to the way the above ItemEditing method worked, but I've ran out of ideas... Any help appreciated. All I have at the moment is...

 Protected Sub ListView1_Updating(ByVal sender As Object, ByVal e As ListViewUpdateEventArgs) Handles ListView1.ItemUpdating

    'ListView1.ItemIndex = e.ItemIndex  'This does not work

    LoadData(Session("SID"))

End Sub

Thanks


Solution

  • Set the EditIndex to -1.

    ListView1.EditIndex = -1