我有一个DataList
,每个数据列表都有label
和button
,我想在为每个数据列表行单击按钮时获得标签的文本吗?我正在使用vb.net
。
我假设您通过设置Button的CommandName属性来处理DataList
的ItemCommand事件。
Sub Item_Command(sender As Object, e As DataListCommandEventArgs)Handles DataList1.ItemCommand
' What command was triggered?
If e.CommandName = "YourCommandName" Then
' Get the Label in the DataListItem of the clicked button
Dim lbl = DirectCast(e.Item.FindControl("Label1"), Label)
Dim labelText = lbl.Text
End If
End Sub