Need help with ItemCommand event

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
 
T

Teemu Keiski

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.
 
G

Gilles T.

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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top