I would like to know how can I get a column name from a gridview? by its number not by name. like : Name|Age|Birthday: ( so name=0 , age=1 etc...)
thanks.
Revisiting this old question.... it's possible to get the field names of the data bound to a GridView with this kind of code. This makes a dictionary of colnum and field name.
private static IDictionary GetGridViewFieldNames(object grid)
{
var names = new Dictionary();
var view = grid as GridView;
if (view != null) {
for (var i = 0; i < view.Columns.Count; i++) {
var field = view.Columns[i] as BoundField;
if (field != null) {
names.Add(i, field.DataField);
}
}
}
return names;
}