Need help with ItemCommand event

Discussion in 'ASP .Net' started by Gilles T., Jan 5, 2004.

  1. Gilles T.

    Gilles T. Guest

    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
     
    Gilles T., Jan 5, 2004
    #1
    1. Advertising

  2. Gilles T.

    Teemu Keiski Guest

    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." <> wrote in message
    news:8ejKb.4853778$...
    > 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
    >
    >
     
    Teemu Keiski, Jan 5, 2004
    #2
    1. Advertising

  3. Gilles T.

    Gilles T. Guest

    Thanks Teemu!


    "Teemu Keiski" <> wrote in message
    news:...
    > 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." <> wrote in message
    > news:8ejKb.4853778$...
    > > 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
    > >
    > >

    >
    >
     
    Gilles T., Jan 5, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    407
    Nathan Sokalski
    May 29, 2006
  2. Brian Smith

    help with ItemCommand event

    Brian Smith, Jul 14, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    137
    Brian Smith
    Jul 14, 2003
  3. Gilles T.

    Need help with ItemCommand event

    Gilles T., Jan 5, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    154
    Gilles T.
    Jan 5, 2004
  4. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    142
    Nathan Sokalski
    May 29, 2006
  5. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    144
    Nathan Sokalski
    May 29, 2006
Loading...

Share This Page