这是我的网格视图。
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False" CellPadding="4"
OnPageIndexChanging="gridview1_PageIndexChanging" ForeColor="#333333" GridLines="None"
OnDataBound="gridview1_DataBound" OnRowDataBound="gridview1_RowDataBound" AllowPaging="true"
PageSize="20" ShowFooter="true" Style="font-size: small; font-family: Verdana;">
<Columns>
<asp:TemplateField HeaderText="Staff No">
<ItemTemplate>
<asp:Label ID="lblsno" runat="server" Text='<%# Bind("Staff_No") %>'>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gross Salary">
<ItemTemplate>
<asp:Label ID="lblGS" runat="server" Text='<%# Bind("GROSS_SALARY") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Account No">
<ItemTemplate>
<asp:Label ID="lblaccno" runat="server" Text='<%# Bind("acc_num") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="gridview2" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowPaging="true"
PageSize="10" ShowFooter="true" Style="font-size: small; font-family: Verdana;">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbldate" runat="server" Text='<%# Bind("DATE") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="E.P.F">
<ItemTemplate>
<asp:Label ID="lblepf" runat="server" Text='<%# Bind("epf") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:Label ID="lblnewepf" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Salary">
<ItemTemplate>
<asp:Label ID="lblns" runat="server"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblnewns" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
如您所见,在第一个网格视图(gridview1)中,它有另一个网格视图(gridview2)。这是我的表:
净工资的价值=总薪资 - E.P.F.
如何计算净薪水的价值?
答案 0 :(得分:1)
更改.ASPX文件中的以下内容。
<asp:TemplateField HeaderText="Net Salary">
<ItemTemplate>
<asp:Label ID="lblns" runat="server" Text='<%# GetNetSalary(Eval("GROSS_SALARY"),Eval("epf")) %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblnewns" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
在.CS文件中添加此
private string GetNetSalary(object grossSalary,object epf)
{
return (grossSalary - epf).ToString();
}
答案 1 :(得分:0)
感谢您抽出宝贵时间阅读我的问题。我已经有了解决方案。
<asp:TemplateField HeaderText="Net Salary">
<ItemTemplate>
<asp:Label ID="lblns" runat="server" Text='<%# Convert.ToDouble(Eval("GROSS_SALARY")) - ConvertToDouble(Eval("epf")) %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblnewns" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>