Okay, I have been giving this some thought, and with a BoundField, you can do something like the following:
And using the DataField property, you can get information about the field that it is bound to. However, when you try and do the following:Code:int maxLength = 11; string forColumn = "FirstName"; foreach (TableCell var in this.GridView1.Rows[0].Cells) { BoundField bf = (var as DataControlFieldCell).ContainingField as BoundField; if (bf != null) { if (bf.DataField == forColumn) { foreach (Control ctr in var.Controls) { if (ctr is TextBox) { (ctr as TextBox).MaxLength = maxLength; } } } } }
You then don't have access to the DataField member, as this is not a Member of TemplateField.Code:foreach (TableCell var in this.GridView1.Rows[0].Cells) { TemplateField tf = (var as DataControlFieldCell).ContainingField as TemplateField; if (tf != null) {
The best you could do is something like this:
Where the ExtractValuesFromCell, is used to find an OrderedDictionary whose Key, in theory, should be the name of the Cell that it is Bound to.Code:foreach (TableCell var in this.GridView1.Rows[0].Cells) { DataControlFieldCell cell = var as DataControlFieldCell; IOrderedDictionary values = new OrderedDictionary(); cell.ContainingField.ExtractValuesFromCell(values, cell, this.GridView1.Rows[0].RowState, true); }
I have only given this a very quick play, but you should be able to get something from it.
Hope that helps!!
Gary





Reply With Quote