จะต้องใช้การ Find Control ตัว GridView ครับ ทำได้ไม่ยาก ตามตัวอย่างนี้ครับ
Code (VB.NET)
Sub Button1_Click(sender As Object, e As EventArgs)
Dim chkCusID As CheckBox
Dim lblID As Label
Dim i As Integer
lblText.Text = ""
For i = 0 To myGridView.Rows.Count - 1
chkCusID = myGridView.Rows(i).FindControl("chkCustomerID")
lblID = myGridView.Rows(i).FindControl("lblCustomerID")
IF chkCusID.Checked = True Then
'*** Have lblID.Text ***'
Me.lblText.Text = Me.lblText.Text & "<br>" & lblID.Text
End IF
Next
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Dim tblID As TextBox
For i = 0 To GridViewDetail.Rows.Count - 1
tblID = GridViewDetail.Rows(i).FindControl("itemcode_detail")
If Not IsNothing(tblID) Then
Response.Write(tblID.Text)
End If
Next
End If
End Sub