Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
Add two columns value and show total in another column
Hold On
7y
220
1
Reply
I have a gridview with 9 columns. I want to get the sum of column
Net Premium
,
VAT
&
Registry Fee. I added another template field called TOTAL. Now, I want to display the sum result in the TOTAL column. But I got this error... attached also the snippets of my front and backend code.
<asp:GridView ID=
"gvListOfIssuedTaxInvoice"
runat=
"server"
BackColor=
"White"
BorderColor=
"#3366CC"
BorderStyle=
"None"
BorderWidth=
"1px"
CellPadding=
"4"
AutoGenerateColumns=
"False"
ShowFooter=
"True"
OnRowDataBound=
"gvListOfIssuedTaxInvoice_RowDataBound"
DataSourceID=
"SqlDataSource1"
>
<Columns>
<asp:TemplateField HeaderText=
"Tax Invoice #"
SortExpression=
"TaxInvoiceNumber"
>
<EditItemTemplate>
<asp:TextBox ID=
"TextBox1"
runat=
"server"
Text=
'<%# Bind("TaxInvoiceNumber") %>'
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label1"
runat=
"server"
Text=
'<%# Bind("TaxInvoiceNumber") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"Date"
SortExpression=
"TransactionDate"
>
<EditItemTemplate>
<asp:TextBox ID=
"TextBox2"
runat=
"server"
Text=
'<%# Bind("TransactionDate") %>'
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label2"
runat=
"server"
Text=
'<%# Bind("TransactionDate") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"Book #"
SortExpression=
"BookNumber"
>
<EditItemTemplate>
<asp:TextBox ID=
"TextBox3"
runat=
"server"
Text=
'<%# Bind("BookNumber") %>'
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label3"
runat=
"server"
Text=
'<%# Bind("BookNumber") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"Customer Name"
SortExpression=
"CustomerName"
>
<EditItemTemplate>
<asp:TextBox ID=
"TextBox4"
runat=
"server"
Text=
'<%# Bind("CustomerName") %>'
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label4"
runat=
"server"
Text=
'<%# Bind("CustomerName") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"Province"
SortExpression=
"Province"
>
<EditItemTemplate>
<asp:TextBox ID=
"TextBox5"
runat=
"server"
Text=
'<%# Bind("Province") %>'
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label5"
runat=
"server"
Text=
'<%# Bind("Province") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"Net Premium"
SortExpression=
"NetPremium"
>
<EditItemTemplate>
<asp:Label ID=
"Label1"
runat=
"server"
Text=
'<%# Eval("NetPremium") %>'
></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label6"
runat=
"server"
Text=
'<%# Bind("NetPremium") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"VAT"
SortExpression=
"VAT"
>
<EditItemTemplate>
<asp:Label ID=
"Label2"
runat=
"server"
Text=
'<%# Eval("VAT") %>'
></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label7"
runat=
"server"
Text=
'<%# Bind("VAT") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"Registry Fee"
SortExpression=
"RegistryFee"
>
<EditItemTemplate>
<asp:Label ID=
"Label3"
runat=
"server"
Text=
'<%# Eval("RegistryFee") %>'
></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=
"Label8"
runat=
"server"
Text=
'<%# Bind("RegistryFee") %>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
"TOTAL"
>
<ItemTemplate>
<asp:Label ID=
"lblTOTAL"
runat=
"server"
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor=
"#99CCCC"
ForeColor=
"#003399"
/>
<HeaderStyle BackColor=
"#003399"
Font-Bold=
"True"
ForeColor=
"#CCCCFF"
/>
<PagerStyle BackColor=
"#99CCCC"
ForeColor=
"#003399"
HorizontalAlign=
"Left"
/>
<RowStyle BackColor=
"White"
ForeColor=
"#003399"
/>
<SelectedRowStyle BackColor=
"#009999"
Font-Bold=
"True"
ForeColor=
"#CCFF99"
/>
<SortedAscendingCellStyle BackColor=
"#EDF6F6"
/>
<SortedAscendingHeaderStyle BackColor=
"#0D4AC4"
/>
<SortedDescendingCellStyle BackColor=
"#D6DFDF"
/>
<SortedDescendingHeaderStyle BackColor=
"#002876"
/>
</asp:GridView>
protected
void
gvListOfIssuedTaxInvoice_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType == DataControlRowType.DataRow)
{
decimal
netpremium = Convert.ToDecimal(e.Row.Cells[6].Text);
decimal
vat = Convert.ToDecimal(e.Row.Cells[7].Text);
decimal
registry = Convert.ToDecimal(e.Row.Cells[8].Text);
Label lblTOTAL = (Label)e.Row.Cells[9].FindControl(
"lblTOTAL"
);
decimal
sum = netpremium + vat + registry;
lblTOTAL.Text += sum.ToString();
}
}
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
Data access in mvc using entity framework
Input string not in correct format