error Handles clause requires a WithEvents variable.

Discussion in 'ASP .Net' started by Moe Sizlak, Jul 26, 2004.

  1. Moe Sizlak

    Moe Sizlak Guest

    Hi,

    I am trying to create an custom event to fill an image control, I keep
    getting the error "Handles clause requires a WithEvents variable." What am I
    missing?

    Moe


    Private Sub dg_details_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles Grid.ItemCreated
    Dim img As New System.Web.UI.WebControls.Image
    img = CType(e.Item.FindControl("image1"),
    System.Web.UI.WebControls.Image)
    Dim d As System.Data.Common.DbDataRecord
    d = e.Item.DataItem
    If Not d Is Nothing Then
    If Not img Is Nothing Then
    Dim strVal As String = "" ' field number in the list
    If Not strVal Is Nothing AndAlso strVal <> "" Then
    img.imageurl = strVal
    else
    img.imageurl = "SecondSpacer.gif"
    End If
    End If
    End If
    End Sub


    <asp:DataGrid
    ID="dg_details"
    AutoGenerateColumns=False
    Width="250"
    HeaderStyle-BackColor="purple"
    HeaderStyle-ForeColor="White"
    HeaderStyle-HorizontalAlign="Center"
    HeaderStyle-Font-Bold="True"
    border="0"
    OnItemCreated="dg_details_ItemCreated"
    Moe Sizlak, Jul 26, 2004
    #1
    1. Advertising

  2. Did you declare "Grid" WithEvents?

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Moe Sizlak" <> wrote in message
    news:...
    > Hi,
    >
    > I am trying to create an custom event to fill an image control, I keep
    > getting the error "Handles clause requires a WithEvents variable." What am

    I
    > missing?
    >
    > Moe
    >
    >
    > Private Sub dg_details_ItemCreated(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridItemEventArgs) Handles Grid.ItemCreated
    > Dim img As New System.Web.UI.WebControls.Image
    > img = CType(e.Item.FindControl("image1"),
    > System.Web.UI.WebControls.Image)
    > Dim d As System.Data.Common.DbDataRecord
    > d = e.Item.DataItem
    > If Not d Is Nothing Then
    > If Not img Is Nothing Then
    > Dim strVal As String = "" ' field number in the list
    > If Not strVal Is Nothing AndAlso strVal <> "" Then
    > img.imageurl = strVal
    > else
    > img.imageurl = "SecondSpacer.gif"
    > End If
    > End If
    > End If
    > End Sub
    >
    >
    > <asp:DataGrid
    > ID="dg_details"
    > AutoGenerateColumns=False
    > Width="250"
    > HeaderStyle-BackColor="purple"
    > HeaderStyle-ForeColor="White"
    > HeaderStyle-HorizontalAlign="Center"
    > HeaderStyle-Font-Bold="True"
    > border="0"
    > OnItemCreated="dg_details_ItemCreated"
    >
    >
    Kevin Spencer, Jul 26, 2004
    #2
    1. Advertising

  3. Moe Sizlak

    Moe Sizlak Guest

    Hi Kevin,

    Can you give me an example?

    Moe

    "Kevin Spencer" <> wrote in message
    news:...
    > Did you declare "Grid" WithEvents?
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Moe Sizlak" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I am trying to create an custom event to fill an image control, I keep
    > > getting the error "Handles clause requires a WithEvents variable." What

    am
    > I
    > > missing?
    > >
    > > Moe
    > >
    > >
    > > Private Sub dg_details_ItemCreated(ByVal sender As Object, ByVal e As
    > > System.Web.UI.WebControls.DataGridItemEventArgs) Handles

    Grid.ItemCreated
    > > Dim img As New System.Web.UI.WebControls.Image
    > > img = CType(e.Item.FindControl("image1"),
    > > System.Web.UI.WebControls.Image)
    > > Dim d As System.Data.Common.DbDataRecord
    > > d = e.Item.DataItem
    > > If Not d Is Nothing Then
    > > If Not img Is Nothing Then
    > > Dim strVal As String = "" ' field number in the list
    > > If Not strVal Is Nothing AndAlso strVal <> "" Then
    > > img.imageurl = strVal
    > > else
    > > img.imageurl = "SecondSpacer.gif"
    > > End If
    > > End If
    > > End If
    > > End Sub
    > >
    > >
    > > <asp:DataGrid
    > > ID="dg_details"
    > > AutoGenerateColumns=False
    > > Width="250"
    > > HeaderStyle-BackColor="purple"
    > > HeaderStyle-ForeColor="White"
    > > HeaderStyle-HorizontalAlign="Center"
    > > HeaderStyle-Font-Bold="True"
    > > border="0"
    > > OnItemCreated="dg_details_ItemCreated"
    > >
    > >

    >
    >
    Moe Sizlak, Jul 27, 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. Guest

    WithEvents ???

    Guest, Dec 24, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    884
    Tom Spink
    Dec 24, 2003
  2. Andreas Klemt
    Replies:
    2
    Views:
    551
    Andreas Klemt
    Jul 5, 2003
  3. Sean
    Replies:
    3
    Views:
    877
    Alan Ferrandiz Langley
    Jun 11, 2004
  4. eino
    Replies:
    1
    Views:
    425
    =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=
    May 8, 2007
  5. dancer
    Replies:
    2
    Views:
    596
    dancer
    Jul 13, 2007
Loading...

Share This Page