Unfortunately this isn't something that has been updated in RC1 and probably won't see the actual release version either. However, a recent project I worked on required a few other extensions of the GridView control (multi-row editing, expanding rows, etc.) so while I was writing my extension I hacked together some code to extract values from a row; it's not very pretty, but it does the job in most cases. For BoundFields I just grabbed the DataField property and used that as the key in the returned dictionary, but for TemplateFields I didn't have that option so I just used the SortExpression property (which means when implementing the grid, you'll have to specify the SortExpression for your TemplateFields even if sorting isn't enabled; if you don't it just creates a key called "KeyX", where 'X' is the column number). I apologize if the forum screws up the formatting; bear with me.
/// <summary>
/// Extracts all the values from the row contained at the specified index.
/// </summary>
/// <param name="rowIndex">The index of the row from which to extract the values.</param>
/// <returns>IOrderedDictionary containing DataField-Value pairs.</returns>
public virtual IOrderedDictionary ExtractRowValues(GridViewRow row)
{
OrderedDictionary fieldValues = new OrderedDictionary();
for(int i=0; i < this.Columns.Count; i++)
{
object value = "";
string field = "";
// Extract value from TemplateField
if(this.Columns
is TemplateField && row.Cells
.Controls.Count > 0)
{
// TODO figure out how to grab DataField from two-way binding
field = ((TemplateField)this.Columns
).SortExpression;
// Search for a control containing a value
foreach(Control c in row.Cells
.Controls)
{
if(c is TextBox) { value = ((TextBox)c).Text; break; }
else if(c is DropDownList) { value = ((DropDownList)c).SelectedValue; break; }
else if(c is CheckBox) { value = ((CheckBox)c).Checked; break; }
}
}
// Extract value from BoundField
else if(this.Columns
is BoundField)
{
field = ((BoundField)this.Columns
).DataField;
if(row.Cells
.Controls.Count > 0)
value = ((TextBox)row.Cells
.Controls[0]).Text;
else
value = row.Cells
.Text;
}
// Add the extracted values to the dictionary
// insert blanks too, so the column count is maintained.
if(field.Length > 0 && !fieldValues.Contains(field))
fieldValues.Add(field, value);
else
fieldValues.Add("Key" + fieldValues.Count, value);
}
return fieldValues;
}