Performing calcualtions on data in gridview

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

Is it possible to perform calculations on data in your gridview in your
ASP, or do you need to do any calculations in the OnRowDataBound event?
Here is what I am trying to do :

<asp:TemplateField HeaderText="Target (%)"
SortExpression="TargetPercentage">
<ItemTemplate>
<asp:Label ID="lblTargetPercentage"
Text='<%# Eval("TargetPercentage")*100 %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Height="24px" Width="50px" />
 
I would make the calculation part of the sql statement or part of the stored procedure so that the gridview simply displays the
calculated results
 
If the calculations required input that was not available within the
database, you could retrieve the dataset with a constant value column
and then perform the calculation on the dataset before binding to the
datagrid.
 
Back
Top