【发布时间】:2015-08-12 03:28:25
【问题描述】:
我认为这可能很容易,但我似乎没有得到它。我在 VB 工作。我在表中动态创建行,但我希望添加一个触发子的“编辑”链接/按钮/事件触发器,但我需要将变量传递给子。代码如下。请注意,我需要传递的变量是一个整数。
Dim CellDescriptionEdit As New TableCell()
RowNameDescription.Cells.Add(CellDescriptionEdit)
CellDescriptionEdit.ID = "CellDescriptionEdit" & UserReader("fldClaimPmtID")
Dim LinkButtonEdit As New LinkButton
LinkButtonEdit.CommandArgument = UserReader("fldClaimPmtID")
LinkButtonEdit.OnClientClick = "LinkButtonEdit_OnClick"
LinkButtonEdit.Text = "EDIT"
CellDescriptionEdit.Controls.Add(LinkButtonEdit)
那么子就长这样了……
Protected Sub LinkButtonEdit_OnClick(sender As Object, e As EventArgs)
'Lots of happy code but for example purposes let's use this...
lblTest.Text = Int32.Parse(btn.CommandArgument)
End Sub
知道如何让它工作吗?
【问题讨论】:
-
感谢您的及时回复。我会把它放在哪里?
-
在
lblTest.Text = (here)行中。但是@LarsTech,Int32.Parse(DirectCast(sender, LinkButton).CommandArgument)不是 VB.NET 中的正确方法吗? -
@VisualVincent 是的,你的方式。我在 c# 模式下。
-
我似乎无法让它工作。我已将其更改为: Protected Sub LinkButtonEdit_OnClick(sender As Object, e As EventArgs) '很多快乐的代码,但出于示例目的,让我们使用它... lblTest.Text = Int32.Parse(DirectCast(sender, LinkButton).CommandArgument ) 结束子
-
有什么问题?有例外吗?
标签: vb.net variables code-behind