As we all know, javasird is a powerful data binding control, which is easy to use and has advantages and disadvantages. I believe everyone knows its interests. Here we will not go into the topic.
First, you must allow the footer of the DG to be displayed. (Used to display the statistical column value)
Second, set the columns to be counted as template columns, edit the item template in the template column, and name the label control in the item template as lblQuantity.
Third, write the following code in the ItemDataBound event of DG:
If (e. Item. ItemIndex> = 0)
{
// Retrieve the total data of the specified Column
Label lblQuantity = (Label) e. Item. Cells [5]. FindControl ("lblQuantity"); // For example, the sixth column is the number.
IntSum + = int. Parse (lblQuantity. Text. ToString ());
}
Else if (e. Item. ItemType = ListItemType. Footer)
{
E. Item. Cells [2]. Text = "<font color = 'red'> total: </font>"; // The total is displayed in the third column.
E. item. cells [5]. text = "<font color = 'red'>" + intSum. toString () + "</font>"; // The number of statistics displayed in column 6 can be adjusted as required.
}
Note: intSum is a global variable. The test code runs normally under VS2003.