情景
问题
问题
代码(VB.NET)
Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gv.Rows(rowIndex)
Dim TxBx As Integer = DirectCast(row.FindControl("txtbox"), TextBox).Text
If (e.CommandName = "EditRow") Then
Me.MyFunction()
End If
End Sub
Private Sub MyFunction()
'How can this function read row dependant variables? i.e TxBx's value
End Sub
备注
我知道该函数应该只在row命令子中编码,但是这个问题的范围是如何不复制函数?
答案 0 :(得分:0)
这可以通过将变量作为参数传递给函数来实现。
<强> ASP.NET 强>
Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gv.Rows(rowIndex)
Dim TxBx As Integer = DirectCast(row.FindControl("txtbox"), TextBox).Text
If (e.CommandName = "EditRow") Then
Me.MyFunction(TxBx)
End If
End Sub
Private Sub MyFunction(TxBx As Integer)
End Sub