String boundFields = String.Empty;
for (int i = 0; i < grd.Columns.Count; i++)
{
DataControlField field = grd.Columns[i];
BoundField bfield = field as BoundField;
if (bfield != null)
boundFields += bfield.DataField + ",";
}
boundFields = boundFields.TrimEnd(',');
The code is from the following link:
http://stackoverflow.com/questions/6449832/get-list-of-datafield-in-gridview