I have an asp.net page called Default.aspx, and it's master page is Site.master. In the Default.aspx, i added a gridview with 3 databound fields and 1 Templatefield, and then, dragged a TextBox inside this templatefield.
I'm trying to get the textbox values for each row in this gridview, using the FindControl method, but it's returning Nothing.
Here is the code that i'm using to retrieve these values:
For Each gvr As GridViewRow In GridView1.Rows
Dim tb As TextBox = DirectCast(gvr.FindControl("TextBox1"), TextBox)
Dim txt As String = tb.Text
MsgBox(txt)
Next
Note: I'm using masterPages, and i'm thinking this is causing the problem.
[edit]
In the Page_load event, to bound the gridview, i'm using the code:
GridView1.DataSource = f.xDa
GridView1.DataBind()
In the Button1, I've added the code:
For Each gvr As GridViewRow In GridView1.Rows
Dim tb As TextBox = DirectCast(gvr.FindControl("TextBox1"), TextBox)
Dim txt As String = tb.Text
MsgBox(txt)
Next
But i'm Always getting an empty textbox.
Thank's everybody!
For Each gvr As GridViewRow In GridView1.Rows Dim tb As TextBox = DirectCast(gvr.FindControl("TextBox1"), TextBox) Dim txt As String = tb.Text MsgBox(txt) Next
– Diego Oliveira Oct 02 '13 at 20:17