views:

784

answers:

2

Hi there, I'm trying get values from a GridView using the following code:

foreach (GridViewRow row in this.dgvEstudios.Rows)
{
    var xy = row.Cells[1].Text;
}

Always get a an empty string ("") as the value returned from .Text, why does this happen? I have set EnableViewState to true

+1  A: 

it could depend on many things.. Where is this code fired in relation to when the GridView is populated (Databind() called)?

Without any context, its hard to say what else it could be.

Jeff Martin
Im using RowDataBound for play with data inside GridView, by the way I will test the first answer, but what about ViewState?
Angel Escobedo
+2  A: 

The cell might have controls inside it (e.g. LiteralControl or an HyperLink). This is what you should be looking for.

row.Cells[1].Controls collection, you should look for.

shahkalpesh
this works! but specifing the index from ControlsCollection like this:row.Cells[1].Controls[1];this is a normal behavior?
Angel Escobedo