Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview with text box template field added dynamically in code behind, entered value to text box. While fetching the text box value, it's returning empty.

Below code i tried to get value.

'*** I entered "Hello" value in text box control before executing below code.

VB
For Each row As GridViewRow In GridviewChild.Rows

            Dim tbSigningGroup As TextBox = DirectCast(row.Cells(4).FindControl("tbSigningGroup" + CStr(row.RowIndex)), TextBox)

            If Not tbSigningGroupIs Nothing Then
                Dim temp As String = tbSigningGroup.Text  ' ****** Returns NULL*******
            End If

Next


'****Any suggestions, where am i doing wrong?

What I have tried:

I used CurrentRow.FindControl("ControlID") method to get the value, but still i am getting empty string as return value.
Posted
Updated 13-Jun-17 1:32am
Comments
Bhola Ram Sahu 29-May-17 6:16am    
You should check that line where you bind the gridview.datasource. Make sure you have put that line in non postback block. seems it will work.
Richard Deeming 30-May-17 7:49am    
FindControl expects the ID of the control as you entered it in the markup. Why are you appending the row index to the ID?

Are you sure it's finding the control? That tbSigningGroup isn't Nothing?

How are you creating the control? Have you considered using a TemplateField instead?

1 solution

 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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900