((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text

romit

Newcomer
Joined
Jun 13, 2011
Messages
1
((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text

I am using this line of code to access the value of textbox which appeared when i clicked on auto generated edit button in gridview.
It is working fine. But my question is that what Controls[0] represents here?
By the syntax it is looking like a collection whose zeroth control is being accessed by me. Then in what scenario would there be need to use Controls[1], Controls[2] ??
 
Just about any container that can hold controls exposes them as a .Controls collection. If the cell only has a single control (the TextBox in your example) then Controls[0] will be the first and only control. If on the other hand there was more than one control in the cell then you would be able to use Controls[1] etc to refer to these other controls.
 
Back
Top