Textbox in gridview asp.net

deepakgates

Broken In
So I dynamically added textbox into gridview in page load event

Dim r, c As Integer
For c = 0 To GridView.HeaderRow.Cells.Count - 1
For r = 0 To GridView.Rows.Count - 1
Dim tb As TextBox = New TextBox
tb.ID = "tb " + r.ToString + " " + c.ToString
GridView.Rows(r).Cells(c).Controls.Add(tb)
Next
Next

And in other event I just cant access those textbox ..

For c = 0 To GridView.HeaderRow.Cells.Count - 1
For r = 0 To GridView.Rows.Count - 1
Dim tbname As String = "tb " + r.ToString + " " + c.ToString
Dim tb = New TextBox
tb = GridView.Rows(r).Cells(c).FindControl(tbname)
Response.Write(tb.Text)
Next
Next

Tried almost everything
Dim tb = New TextBox
tb = GridView.Rows(r).Cells(c).FindControl(tbname)
tb = CType(GridView.Rows(r).Cells(c).FindControl(tbname), TextBox)
IT always gives null exception

Searched again and again with no gain SO thinkdigit seemed right spot!!

Thanks!!
 
Last edited:
Top Bottom