Need help with ItemCommand event

  • Thread starter Thread starter Gilles T.
  • Start date Start date
G

Gilles T.

I have on the same page this code:
<script language="VB" runat="server">
...
...
Private Sub subDatagrid_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
subDatagrid.ItemCommand
...
End Sub
...
...
</script>
<ASP:DataGrid id="subDatagrid" runat="server"
AllowSorting="False"
...
...

I have this error:
Handles clause requires a WithEvents variable
at this line: Private Sub subDatagrid_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
subDatagrid.ItemCommand


If I add this line in top:
Protected WithEvents subDatagrid As System.Web.UI.WebControls.DataGrid

I have this error:
'subDatagrid' is already declared as 'Protected Dim subDatagrid As
System.Web.UI.WebControls.DataGrid' in this class.

What is the problem?
Can you help me please?

Thanks
 
Hi,

as you use inline code put it this way:

Code:
Protected Sub subDatagrid_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
...
End Sub

(i.e no handles clause at all).

Then for the DataGrid:
Code:
<asp:DataGrid id="subDatagrid" runat="server"
OnItemCommand="subDatagrid_ItemCommand" ...>
...
</asp:DataGrid>

i.e you specify the event handler method declaratively in aspx with
On<EventName> attribute.
 
Thanks Teemu!


Teemu Keiski said:
Hi,

as you use inline code put it this way:

Code:
Protected Sub subDatagrid_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
...
End Sub

(i.e no handles clause at all).

Then for the DataGrid:
Code:
<asp:DataGrid id="subDatagrid" runat="server"
OnItemCommand="subDatagrid_ItemCommand" ...>
..
</asp:DataGrid>

i.e you specify the event handler method declaratively in aspx with
On<EventName> attribute.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

Gilles T. said:
I have on the same page this code:
<script language="VB" runat="server">
...
...
Private Sub subDatagrid_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
subDatagrid.ItemCommand
...
End Sub
...
...
</script>
<ASP:DataGrid id="subDatagrid" runat="server"
AllowSorting="False"
...
...

I have this error:
Handles clause requires a WithEvents variable
at this line: Private Sub subDatagrid_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
subDatagrid.ItemCommand


If I add this line in top:
Protected WithEvents subDatagrid As System.Web.UI.WebControls.DataGrid

I have this error:
'subDatagrid' is already declared as 'Protected Dim subDatagrid As
System.Web.UI.WebControls.DataGrid' in this class.

What is the problem?
Can you help me please?

Thanks
 
Back
Top