我正在将某些类从C#
转换为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\
答案 0 :(得分:6)
您无需在VB.NET中以编程方式注册事件处理程序。您可以使用aspx标记来声明事件处理程序(OnRowDataBound = "RowDataBoundHandler"
)或使用Handles
clause。您甚至可以使用一个控件,用逗号分隔它们。
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) _
Handles GridView1.RowDataBound
End Sub
如果您想手动添加,请使用AddHandler
:
AddHandler Me.GridView1.RowDataBound, AddressOf RowDataBoundHandler
答案 1 :(得分:3)
如果要手动绑定事件,请尝试使用AddHandler
:
AddHandler Me.mGrid.RowDataBound, AddressOf RowDataBoundHandler
或者您可以在ASPX标记中绑定事件:
<asp:GridView ... RowDataBound="RowDataBoundHandler" runat="server" />
或者使用Tim Schmelter的方法。
答案 2 :(得分:3)
使用它代替,这是VB的方式。 VB使用AddHandler来标识事件,而AddressOf指向委托。
AddHandler mGrid.RowDataBound, AddressOf RowDataBoundHandler