VB.Net Calculating values using GridView bound fields and outputting value to another field

StackOverflow https://stackoverflow.com/questions/15920231

문제

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