Problem with conversion from C# to VB.NET

Discussion in 'ASP .Net Web Controls' started by PatLaf, Feb 3, 2004.

  1. PatLaf

    PatLaf Guest

    Hello to all, I converted a response I recieved in this newsgroup last week to vb.net but I can't convert this sub correctly. Can anyone help....the dgDeftects.ItemCommand never fires and I think it's because it's not wired up correctly.




    Private Sub InitializeComponent()
    dgDefects.ItemCommand += New System.Web.UI.WebControls.DataGridCommandEventHandler(AddressOf dgDefects_ItemCommand)

    Me.Load += New System.EventHandler(Me.Page_Load)
    End Sub 'InitializeComponent

    Private Sub dgDefects_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)

    Dim ovalue As Integer

    ovalue = Integer.Parse(CType(e.Item.Controls(2), TableCell).Text)

    If e.CommandName = "Increase" Then
    CType(e.Item.Controls(2), TableCell).Text = (ovalue + 1).ToString()
    Else
    CType(e.Item.Controls(2), TableCell).Text = (ovalue - 1).ToString()
    End If
    End Sub 'dgDefects_ItemCommand

    If Not Page.IsPostBack Then
    Dim dt As New DataTable("MyTable")

    dt.Columns.Add("IntValue", System.Type.GetType("System.Int16"))
    dt.Columns.Add("StrValue", System.Type.GetType("System.String"))

    Dim dr As DataRow = dt.NewRow()

    dr(0) = 1

    dt.Rows.Add(dr)

    dr = dt.NewRow()

    dr(0) = 2

    dt.Rows.Add(dr)

    dgDefects.DataSource = dt

    dgDefects.DataBind()
    End If
    End Sub 'Page_Load

    this is all the code that I have but the ide is complaining about the initialize component method.
    Thanks in advance,
    Patrick Laferriere
    PatLaf, Feb 3, 2004
    #1
    1. Advertising

  2. PatLaf

    PatLaf Guest

    Errrr.....duh....I figured it out.....

    it's this simple I thin

    AddHandler dgDefects.ItemCommand, AddressOf dgDefects_ItemComman

    that got the command event to fire and it seems to work...

    thanks
    PatLaf, Feb 3, 2004
    #2
    1. Advertising

  3. Hi Patrick,

    Yes, C# use += operator to add event handler for object, in VB.net the
    alternative is Addhanlder keyword.
    Also, you should use AddressOf keyword to retrieve function's address.

    I am glad you figure it out yourself, if you have further concern, please
    feel free to post, I will help you.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Feb 4, 2004
    #3
  4. PatLaf

    Felbrigg Guest

    If your converting to VB the problem is most likely that the
    InitialiseComponent method code show here is not needed. If the dgDefects
    object is declared "WithEvents" you should need to manually wire the events
    shown here.

    "PatLaf" <> wrote in message
    news:...
    > Hello to all, I converted a response I recieved in this newsgroup last

    week to vb.net but I can't convert this sub correctly. Can anyone
    help....the dgDeftects.ItemCommand never fires and I think it's because it's
    not wired up correctly.
    >
    >
    >
    >
    > Private Sub InitializeComponent()
    > dgDefects.ItemCommand += New

    System.Web.UI.WebControls.DataGridCommandEventHandler(AddressOf
    dgDefects_ItemCommand)
    >
    > Me.Load += New System.EventHandler(Me.Page_Load)
    > End Sub 'InitializeComponent
    >
    > Private Sub dgDefects_ItemCommand(ByVal source As Object, ByVal e As

    System.Web.UI.WebControls.DataGridCommandEventArgs)
    >
    > Dim ovalue As Integer
    >
    > ovalue = Integer.Parse(CType(e.Item.Controls(2), TableCell).Text)
    >
    > If e.CommandName = "Increase" Then
    > CType(e.Item.Controls(2), TableCell).Text = (ovalue +

    1).ToString()
    > Else
    > CType(e.Item.Controls(2), TableCell).Text = (ovalue -

    1).ToString()
    > End If
    > End Sub 'dgDefects_ItemCommand
    >
    > If Not Page.IsPostBack Then
    > Dim dt As New DataTable("MyTable")
    >
    > dt.Columns.Add("IntValue",

    System.Type.GetType("System.Int16"))
    > dt.Columns.Add("StrValue",

    System.Type.GetType("System.String"))
    >
    > Dim dr As DataRow = dt.NewRow()
    >
    > dr(0) = 1
    >
    > dt.Rows.Add(dr)
    >
    > dr = dt.NewRow()
    >
    > dr(0) = 2
    >
    > dt.Rows.Add(dr)
    >
    > dgDefects.DataSource = dt
    >
    > dgDefects.DataBind()
    > End If
    > End Sub 'Page_Load
    >
    > this is all the code that I have but the ide is complaining about the

    initialize component method.
    > Thanks in advance,
    > Patrick Laferriere
    Felbrigg, Feb 4, 2004
    #4
    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. Tony
    Replies:
    0
    Views:
    521
  2. Brian Henry

    Conversion errors from .NET 2.0 ASP.NET...

    Brian Henry, Oct 31, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    1,790
    Brian Henry
    Nov 1, 2005
  3. =?Utf-8?B?Qm9i?=
    Replies:
    2
    Views:
    397
    =?Utf-8?B?Qm9i?=
    Jan 30, 2006
  4. Bonggoy Cruz
    Replies:
    7
    Views:
    4,011
    =?Utf-8?B?RHVzdGluIHZhbiBkZSBTYW5kZSBbTUNBRF0=?=
    Apr 14, 2006
  5. , India
    Replies:
    2
    Views:
    456
    Fraser Ross
    Sep 15, 2009
Loading...

Share This Page