Http://www.cnblogs.com/RChen/archive/2008/09/23/1296721.html
Are you still using this code?
VaR txtname = grid1.rows [E. rowindex]. cells [0]. findcontrol ("txtname") as textbox;
If (txtname! = NULL)
{
// Read value
//
}
In fact, these operations (search for controls in cells and try to get the values) have been encapsulated. Now, you only need to callExtractvaluesfromcellMethod.
This method is also supported by many column types:
Datacontrolfield, boundfield, autogeneratedfield, checkboxfield, imagefield, templatefield, dynamicfield
You can use it in the rowupdating, rowdeleting, and other events of the gridview. This method can be used to extract values to the required dictionary and then read from the dictionary. These dictionaries include E. Keys, E. newvalues, and E. oldvalues.
Example code:
// Update
Protected void grid1_rowupdating (Object sender, gridviewupdateeventargs E)
{
VaR ROW = grid1.rows [E. rowindex];
// Extract the value of the ID field
Grid1.columns [0]. extractvaluesfromcell (
E. Keys,
Row. cells [0] As datacontrolfieldcell,
Datacontrolrowstate. Edit,
True/* include readonly */);
// Extract the value of the Name field
Grid1.columns [1]. extractvaluesfromcell (
E. newvalues,
Row. cells [1] As datacontrolfieldcell,
Datacontrolrowstate. Edit,
True/* include readonly */);
VaR id = int. parse (E. Keys ["ID"]. tostring ());
VaR name = (string) E. newvalues ["name"];
// Perform related database update operations
//
}
In this way, we can use boundfield as much as possible in most cases, and can correctly read the value during editing, saving a bunch of custom templatefield code.