Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vb.net函数中将任何控件作为参数传递_Vb.net_Function_Parameters_Controls - Fatal编程技术网

在vb.net函数中将任何控件作为参数传递

在vb.net函数中将任何控件作为参数传递,vb.net,function,parameters,controls,Vb.net,Function,Parameters,Controls,我有一个如下的vb.net函数,其中我传递了一个复选框控件名作为参数 Public Function emaildata(ByVal grdv As GridView, ByVal ctrl As String, ByVal celpos As Integer) As GridView Dim comm As OleDbCommand = New OleDbCommand() Dim bpv As String = "" Dim gv As New

我有一个如下的vb.net函数,其中我传递了一个复选框控件名作为参数

Public Function emaildata(ByVal grdv As GridView, ByVal ctrl As String, ByVal celpos As Integer) As GridView
        Dim comm As OleDbCommand = New OleDbCommand()
        Dim bpv As String = ""
        Dim gv As New GridView
        For Each gvrow As GridViewRow In grdv.Rows
            Dim chkbx As CheckBox = CType(gvrow.FindControl(ctrl), CheckBox)
            If chkbx.Checked Then
                If bpv <> "" Then
                    bpv += ","
                End If
                bpv += gvrow.Cells(celpos).Text
                comm.CommandText = "SELECT chq_num Cheque#,to_char(bpv_amt,'9,999,999,999') Amount,vch_nar Narration,bnf_nam PartyName,acc_des Bank from  CHECK_DATA where bpv_num in(" & bpv.ToString() & ") and BPV_DTE=to_date('" & TreeView2.SelectedValue & "')"
                comm.CommandType = CommandType.Text
                comm.Connection = con
                Dim da As New OleDbDataAdapter(comm)
                Dim ds As New DataSet
                da.Fill(ds)
                gv.DataSource = ds
                gv.DataBind()
            End If
        Next
        Return gv
    End Function

问题是,我必须对radiobutton和文本框使用相同的函数,我不想为所有类型的控件编写单独的函数。我想将控件检测为参数和。例如,如果我传递文本框,则函数的行为应类似于文本框;如果为radio,则为radio;如果为checkbox,则为radio;如果为checkbox,则为相同的行为这个。我有这三个控件来传递函数,我想为这些控件创建一个自动检测方法

您需要将ctrl作为控件发送它是所有控件的基类作为参数

您需要使用latebinding,并且需要为每个控件类型编写单独的案例

以下代码仅适用于复选框

Dim chkbx As CheckBox = CType(gvrow.FindControl(ctrl), CheckBox)
If chkbx.Checked Then
对于文本框和单选按钮,您需要编写额外的代码

Public Function emaildata(ByVal grdv As GridView, ByVal ctrl As Control, ByVal celpos As Integer) As GridView

 If TypeOf ctrl Is Button Then

 ElseIf TypeOf ctrl Is RadioButton Then 

 Else

 EndIf

先生,我问的是附加代码,请您出示一些我发布的问题的示例代码,我可以检查传递控件的条件是文本还是无线电,或者检查,然后我会做一些事情首先检查哪种类型的控件,然后您可以继续下一行代码。那么我如何管理这一行以传递控件名称字符串Dim chkbx As CheckBox=CTypegvrow.FindControlctrl,复选框