In the gridview, I usually adopt two methods to bind the property after the data source is bound.
One is boundfield. You only need to set the corresponding attribute name of datafield;
For example:
<Asp: boundfield headertext = "series" datafield = "Catena" itemstyle-width = "10%"/>
Another is templatefield, which is used to process special displays;
For example:
<Asp: templatefield headertext = "annual sales">
<Itemtemplate>
<% # Getsalesvolumes (container. dataitem) %>
</Itemtemplate>
<Itemstyle width = "10%" horizontalalign = "center"/>
</ASP: templatefield>
However, some events bound to rowdatabound often fail to obtain the text value in templatefield;
The value of row. cells [Index]. Text is "";
Later I checked some information and thought about it. I found that templatefield is a container. It is a sub-container with a custom display value;
Debugging, monitoring, and Discovery
<Itemtemplate>
<% # Getsalesvolumes (container. dataitem) %>
</Itemtemplate>
Row. cells [Index]. Controls. Count = 1 in the write method; I found that the data type is databoundliteralcontrol;
Therefore, the method for getting the value of the Column cell is as follows:
(Databoundliteralcontrol) Row. cells [Index]. controls [0]). Text. Trim ();
If the templatefield contains multiple child controls, obtain the controls (type: controlcollection) of cells [Index] to obtain the corresponding child controls cyclically and perform corresponding operations;