Somthing like this might do the job:
private string CellCombination(IEnumerable<string> values)
{
string result = "";
foreach (string s in values)
{
if (!string.IsNullOrWhiteSpace(s)) result += string.Format("{0},", s);
}
return result.Trim(',');
}</string>
Or the same thing using Linq
private string CellCombination(IEnumerable<string> values)
{
string result = values.Where(s => !string.IsNullOrWhiteSpace(s)).Aggregate("", (current, s) => current + string.Format("{0},", s));
return result.Trim(',');
}
To use it, just pass in your cells into the function as an enumerable collection.
So something like this:
e.Row.Cells[1].Text = CellCombination(new [] {e.Row.Cells[1].Text, e.Row.Cells[2].Text, e.Row.Cells[3].Text });