2013-02-10 44 views
0

它具有帶LayoutTemplate,ItemTemplate和EditTemplate的ListView。列表視圖只顯示一個項目。 ItemTemplate中與點擊它時觸發的CommandName = '編輯' 的EditButton ...如何在ListView中更新到ItemTemplate後切換回EditTemplate

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 

的EditTemplate有UpdateButton與CommandName的 '更新' 點擊它時觸發...

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 

以上的作品很棒。我的問題是我現在如何返回到ItemTemplate視圖。我知道我必須使用ItemUpdating方法,類似於上述ItemEditing方法的工作方式,但我已經用完了想法...任何幫助表示讚賞。所有我目前所面對的是...

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 

感謝

回答

2

設置EditIndex-1

ListView1.EditIndex = -1 
相關問題