vb.net 按钮点击事件调用函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31698630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:21:04  来源:igfitidea点击:

Call function on button click event

vb.net

提问by Dilip

How do I call this vb.net function on the button click event?

如何在按钮单击事件上调用此 vb.net 函数?

Private Sub GridView_UDGReport_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound

    For rowIndex As Integer = GridView_UDGReport.Rows.Count - 2 To 0 Step -1
        Dim gviewRow As GridViewRow = GridView_UDGReport.Rows(rowIndex)
        Dim gviewPreviousRow As GridViewRow = GridView_UDGReport.Rows(rowIndex + 1)
        For cellCount As Integer = 0 To gviewRow.Cells.Count - 1
            If gviewRow.Cells(cellCount).Text = gviewPreviousRow.Cells(cellCount).Text Then
                If gviewPreviousRow.Cells(cellCount).RowSpan < 2 Then
                    gviewRow.Cells(cellCount).RowSpan = 2
                Else
                    gviewRow.Cells(cellCount).RowSpan = gviewPreviousRow.Cells(cellCount).RowSpan + 1
                End If
                gviewPreviousRow.Cells(cellCount).Visible = False
            End If
        Next
    Next
End Sub

回答by Pradeep Kumar

Since you are not using the parameters anyways, you can simply call the method with Nothingas parameter.

由于您无论如何都没有使用参数,因此您可以简单地使用Nothing作为参数调用该方法。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    GridView_UDGReport_DataBound1(Nothing, Nothing)
End Sub

回答by Josh

Append the first line so that the sub handles more than one event, as follows:

附加第一行,以便子处理多个事件,如下所示:

Private Sub GridView_UDGReport_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound, Button1.Click

Alternatively, if you need your Click event to run some other code in addition to calling this sub, do this:

或者,如果除了调用此 sub 之外,您还需要 Click 事件来运行其他一些代码,请执行以下操作:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    'do something
    GridView_UDGReport_DataBound1(sender, e)
    'do something else
End Sub