它有一个带有LayoutTemplate,ItemTemplate和EditTemplate的ListView。列表视图只显示一个项目。 ItemTemplate为EditButton,CommandName ='Edit',单击时触发......
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有一个带有CommandName'Update'的UpdateButton,当点击它时触发......
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 View。我知道我必须使用类似于上述ItemEditing方法工作方式的ItemUpdating方法,但我已经用完了想法...任何帮助表示感谢。我现在所拥有的只是......
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
由于
答案 0 :(得分:4)
将EditIndex
设置为-1
。
ListView1.EditIndex = -1