I\'m trying to write a small method to loop through and find a GridView Column by its Index, since it can change position based on what might be visible.
GridView
This way, works for me (.NET Gridview):
private int GetColumnIndexByName(GridView grid, string name) { for (int i = 0; i < grid.HeaderRow.Cells.Count; i++) { if (grid.HeaderRow.Cells[i].Text.ToLower().Trim() == name.ToLower().Trim()) { return i; } } return -1; }