我有一个gridview我已经使用标签自定义gridview ..我想将单元格2中的标签复制到gridview外的文本框中吗?
答案 0 :(得分:2)
由于您的标签位于GridView中,因此您必须遍历GridView中的行。您可以使用GridView的RowDataBound事件遍历行并访问内部控件的值。像这样......
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If Not e.Row.DataItem Is Nothing Then
Dim lbl As Label = CType(e.Row.Cells(1).FindControl("YourLabelName"), Label)
If lbl.Text = "Copy" Then
TextBox1.Text = lbl.Text
End If
End If
End If
End Sub
或者如果要复制特定的行值,则
Dim lbl As Label = DirectCast(DirectCast(e.Item.FindControl("GridView1"), GridView).Rows(0).FindControl("YourLabelName"), Label)
TextBox1.Text = lbl.Text