Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im having gridview with one Checkbox1 and the rest is columns, but the vital one is Amount Column.if I checked 3 checkboxes it must calculate Amount based on checked checkboxes. Any ideas please help

What I have tried:

My gridview

<asp:GridView ID="GridView2" runat="server" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating" DataKeyNames="CallID" AutoGenerateColumns="False" Width="1342px" ShowFooter="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCreated="GridView1_RowCreated" style="margin-top: 0px" OnRowDataBound="GridView2_RowDataBound">
<columns><asp:templatefield headertext="">
<itemtemplate>
<asp:CheckBox ID="CheckBox2" runat="server">



<asp:TemplateField HeaderText="Company name" Visible="False">
<itemtemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("CallID") %>'>



<edititemtemplate>
<asp:TextBox ID="txtCompanyName" runat="server" Text=' <%# Eval("CallID") %>'>
<asp:RadioButton ID ="txtyes" runat ="server" Text ="" />



<asp:TemplateField HeaderText="NewNam">
<itemtemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("NewNam") %>'>

<edititemtemplate>
<asp:TextBox ID="txtCompanyName" runat="server" Text=' <%# Eval("NewNam") %>'>



<asp:TemplateField HeaderText="Called No">
<itemtemplate>
<asp:Label ID="Label61" runat="server" Text='<%# Eval("CalledNo") %>'>

<edititemtemplate>
<asp:TextBox ID="txtCompanyName" runat="server" Text=' <%# Eval("CalledNo") %>'>




<asp:TemplateField HeaderText="Call Extension">
<itemtemplate>
<asp:Label ID="Label51" runat="server" Text='<%# Eval("CallExt") %>'>

<edititemtemplate>
<asp:TextBox ID="txtPostalAddress" runat="server" Text=' <%# Eval("CallExt") %>'>



<asp:TemplateField HeaderText="Call Duration">
<itemtemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("CallDuration") %>'>

<edititemtemplate>
<asp:TextBox ID="txtResidentialAddress" runat="server" Text=' <%# Eval("CallDuration") %>'>



<asp:TemplateField HeaderText="Amount">
<itemtemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("Amount") %>'>

<edititemtemplate>
<asp:TextBox ID="txtWebSite" runat="server" Text=' <%# Eval("Amount") %>'>



<asp:TemplateField HeaderText="tmpNewNam" Visible="False">
<itemtemplate>
<asp:Label ID="Label50" runat="server" Text='<%# Eval("tmpNewNam") %>'>

<edititemtemplate>
<asp:TextBox ID="txtIfOtherSpecify" runat="server" Text=' <%# Eval("tmpNewNam") %>'>



<emptydatatemplate>
<asp:RadioButton ID="RadioButton1" runat="server" />
 
<asp:RadioButton ID="RadioButton2" runat="server" />



<HeaderStyle BackColor="#00274F" ForeColor="White" />


Code Behind on button click

double sum = 0;
foreach (GridViewRow gvr in GridView2.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("CheckBox2");
if (cb.Checked)
{
double amount = Convert.ToDouble(gvr.Cells[6].Text.Replace(" ", ""));
sum += amount;
}


txtbusiness.Text = sum.ToString();

}
}


Error that i'm getting

Input string was not in a correct format.

Please help. Thanks in advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900