0

我正在将一些类从C#to转换为VB.NET,此行无法正确转换。我尝试了一些在线转换器,但它们似乎不起作用。

this.mGrid.RowDataBound += new GridViewRowEventHandler(RowDataBoundHandler);

转换后VB.NET不起作用。

Me.mGrid.RowDataBound += New GridViewRowEventHandler(RowDataBoundHandler)

以下是我从中得到的两个错误。谁能帮帮我,因为我的大脑现在已经死了。

谢谢,

Error 4 Delegate 'System.Web.UI.WebControls.GridViewRowEventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. C:\My Projects\PMS\App_Code\GridViewHelper.vb 110 62 C:\My Projects\PMS\

Error 3 'Public Event RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\My Projects\PMS\App_Code\GridViewHelper.vb 110 9 C:\My Projects\PMS\

4

3 回答 3

6

您不需要在 VB.NET 中以编程方式注册事件处理程序。您可以使用 aspx 标记来声明事件处理程序(OnRowDataBound = "RowDataBoundHandler")或使用Handles子句。您甚至可以将一个用于多个控件,用逗号分隔它们。

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) _
    Handles GridView1.RowDataBound
End Sub

如果您想手动添加它,请使用AddHandler

AddHandler Me.GridView1.RowDataBound, AddressOf RowDataBoundHandler
于 2013-01-29T16:42:57.233 回答
3

AddHandler如果要手动绑定事件,请尝试使用:

AddHandler Me.mGrid.RowDataBound, AddressOf RowDataBoundHandler

或者您可以在 ASPX 标记中绑定事件:

<asp:GridView ... RowDataBound="RowDataBoundHandler" runat="server" />

或者使用 Tim Schmelter 的方法。

于 2013-01-29T16:41:23.490 回答
3

改用它,这是 VB 的做法。VB 使用 AddHandler 来标识事件,AddressOf 指向委托。

AddHandler mGrid.RowDataBound, AddressOf RowDataBoundHandler
于 2013-01-29T16:41:34.673 回答