CancelCommand Event Handler Not Firing

S

Scott M.

I have an asp:DataGrid 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
 
K

Ken Charles MCSD

Hi,

This is obvious but have you confirmed that your event handler is set
up properly in InitializeComponent?

Ken
 
S

Scott M.

Forgive me, but I'm not sure I know what you mean. What is there to set up?
I didn't have to set anything up to get all the other events to fire
correctly (and all the other events do fire).
 
A

awbacker

I think someone has auto-c#-answer turned on. Unless you need to
explicitly bind (or even can) them in vB.
 
S

Scott M.

You do not need to explicitly bind an eventhandler to it's object in VB.NET
(unless we are talking about custom objects - which we aren't).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top