[英]Display calculate value in new column of grid view
Working with gridview in asp.net, I am displaying data in gridview from database, but i had 2 columns grossamount and deductionamount 在asp.net中使用gridview,我在gridview中显示来自数据库的数据,但我有2列grossamount和deductionamount
Need pass sum of both the value and subtract ex:sum(gross)-sum(deduction) = sub amount and also should take based on type if type ="g" 需要通过值和减去ex的总和:sum(gross)-sum(扣除)=子数量,如果type =“g”,也应根据类型取得
gross data should sum and vice versa dispaly ex: 总数据应该总和,反之亦然显示:
<asp:TemplateField ItemStyle-Width="13%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Eval("PayeeAmount")%>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="middle">
<asp:TextBox ID="txtAmount" Enabled="false" runat="server" Text='<%# Bind("PayeeAmount")%>'
CssClass="black_normal" Width="180px" Wrap="true" TextMode="SingleLine" MaxLength="20"
ValidationGroup="GSave"></asp:TextBox>
<ajaxToolkit:FilteredTextBoxExtender ID="fltrDescriptionPayeeDeductionmount" runat="server"
FilterType="Custom" FilterMode="InvalidChars" InvalidChars="'abcdefghijklmnopqrstuvwxyz@!#$%^&*%<> ,"
TargetControlID="txtPayeeDeductionAmount">
</ajaxToolkit:FilteredTextBoxExtender>
</td>
</tr>
</table>
</EditItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
Calculate this values grossamount - deductionamount= subtract amount. 计算此值grossamount - deductionamount =减去金额。
This subtraction amount column is not in database. 此减法量列不在数据库中。 How to customize column and display data in grid view column?
如何在网格视图列中自定义列和显示数据?
You can use your query and create a column which has the required data and bind it to grid. 您可以使用查询并创建包含所需数据的列并将其绑定到网格。
You can create a template field as following 您可以创建模板字段,如下所示
<asp:TemplateField ItemStyle-Width="13%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server"
Text='<%# Int32.Parse(Eval("grossamount").ToString())-Int32.Parse(Eval("deductionamount").ToString())%>'>
</asp:Label>
</ItemTemplate>
if your data is Int32
or cast to some other type as you require. 如果您的数据是
Int32
或根据需要转换为其他类型。
<script type="text/javascript">
function Calculation(TWD, AWD, THD, TTL, TOTALHOLIDAYS) {
var TWD = $(document.getElementById(TWD)).html();
var AWD = $(document.getElementById(AWD)).val();
var THD =$( document.getElementById(THD)).val();
var TotalHolidays = TOTALHOLIDAYS;
var TotalTakenLeave = (parseInt( TWD) + parseInt(TotalHolidays)) - (parseInt(THD) +parseInt( AWD))
$('#' + TTL).html( TotalTakenLeave);
}
</script>
<script type="text/javascript">
function Calculation(TWD, AWD, THD, TTL, TOTALHOLIDAYS) {
var TWD = $(document.getElementById(TWD)).html();
var AWD = $(document.getElementById(AWD)).val();
var THD =$( document.getElementById(THD)).val();
var TotalHolidays = TOTALHOLIDAYS;
var TotalTakenLeave = (parseInt( TWD) + parseInt(TotalHolidays)) - (parseInt(THD) +parseInt( AWD))
$('#' + TTL).html( TotalTakenLeave);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.