You can't do like this. When you click the button: B_Load
, then GridView is NOT in Edit mode. And this is why you can't get the TextBox
, which is in EditItemTemplate
.
You can only get the controls inside <ItemTemplate>
in your button click as gridview is in Normal display Mode. <EditItemTemplate>
controls are rendered only when GridView enters Edit
mode.
So, you need to get the value of the Label: Label1
here actually, which has the same value and is inside <ItemTemplate>
.
Dim Lbl_Control As Label= CType(row.FindControl("Label1"), Label)
// button click as usual, just get and check the value of Label control, rather than TextBox control.
Protected Sub B_Load_Click(ByVal sender As Object, ByVal e As EventArgs) '(sender As
Object, e As System.EventArgs) Handles B_Load.Click
Dim FullText As String = ""
For Each row As GridViewRow In GV_Comments.Rows
Dim CB_Control As CheckBox = CType(row.FindControl("Comment_Select"),
CheckBox)
Dim Lbl_Control As Label= CType(row.FindControl("Label1"), Label)
If CB_Control IsNot Nothing AndAlso CB_Control.Checked AndAlso Lbl_Control
IsNot Nothing Then
FullText = FullText & Lbl_Control.Text & "<br/>"
End If
Next row
CompiledText.Text = FullText.ToString
End Sub