Within a GridView is it possible, using the output of two or more asp BoundFields, to calculate a value and then output this in it's own field?

eg calculating % from two bound fields:

Amount    Total    % (calculated field from Amount / Total * 100)
137       69       50.4 

or is it better to generate this calculation using SQL and output the result to it's own BoundField?

有帮助吗?

解决方案

Use TemplateField instead of the BoundField

<asp:TemplateField HeaderText="Calculation">
    <ItemTemplate>
        <asp:TextBox ID="tb" runat="server" 
                     Text='<% ((Convert.ToDecimal(Eval("Amount"))/Convert.ToDecimal(Eval("Total")))*Convert.ToDecimal(100)).ToString() %>' >  
        </asp:TextBox>
   </ItemTemplate>
</asp:TemplateField>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top