S
Scott M.
I have an aspataGrid control with EnableViewState=False. I am calling
DataBind on both the non-postback and the postback. I am persisting the
state of the grid myself and restoring the state (selectedItem, editItem,
sortCommand, etc.). Everything is working just fine EXCEPT the
CancelCommand event is not firing. All the other events ARE firing.
Here is the CancelCommand:
Private Sub dg_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.CancelCommand
viewstate.Add("editItem", -1)
dg.EditItemIndex = -1
RestoreState()
End Sub
Private Sub RestoreState()
'Call this method in each DataGrid event handler
'to restore the new grid back to its previous state
If Not IsNothing(viewstate.Item("editItem")) Then
dg.EditItemIndex = CType(viewstate.Item("editItem"), Integer)
End If
If Not IsNothing(viewstate.Item("currentPage")) Then
dg.CurrentPageIndex = CType(viewstate.Item("currentPage"), Integer)
End If
If Not IsNothing(viewstate.Item("currentSelection")) Then
dg.SelectedIndex = CType(viewstate.Item("currentSelection"),
Integer)
End If
If Not IsNothing(viewstate.Item("currentSort")) Then
Dim dv As New DataView(ds.Tables(0))
dv.Sort = CType(viewstate.Item("currentSort"), String)
dg.DataSource = dv
End If
dg.DataBind()
End Sub
DataBind on both the non-postback and the postback. I am persisting the
state of the grid myself and restoring the state (selectedItem, editItem,
sortCommand, etc.). Everything is working just fine EXCEPT the
CancelCommand event is not firing. All the other events ARE firing.
Here is the CancelCommand:
Private Sub dg_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.CancelCommand
viewstate.Add("editItem", -1)
dg.EditItemIndex = -1
RestoreState()
End Sub
Private Sub RestoreState()
'Call this method in each DataGrid event handler
'to restore the new grid back to its previous state
If Not IsNothing(viewstate.Item("editItem")) Then
dg.EditItemIndex = CType(viewstate.Item("editItem"), Integer)
End If
If Not IsNothing(viewstate.Item("currentPage")) Then
dg.CurrentPageIndex = CType(viewstate.Item("currentPage"), Integer)
End If
If Not IsNothing(viewstate.Item("currentSelection")) Then
dg.SelectedIndex = CType(viewstate.Item("currentSelection"),
Integer)
End If
If Not IsNothing(viewstate.Item("currentSort")) Then
Dim dv As New DataView(ds.Tables(0))
dv.Sort = CType(viewstate.Item("currentSort"), String)
dg.DataSource = dv
End If
dg.DataBind()
End Sub