Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm 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

XML
<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">
          
     </itemtemplate> 

 <asp:TemplateField HeaderText="Company name" Visible="False">
            <itemtemplate>
        <asp:Label ID="Label4" runat="server" Text='<%# Eval("CallID") %>'>
        <br />
        </itemtemplate>
        <edititemtemplate>
        <asp:TextBox ID="txtCompanyName" runat="server" Text=' <%# Eval("CallID") %>'>
        <asp:RadioButton ID ="txtyes" runat ="server" Text ="" />
        </edititemtemplate>
        

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

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

        <asp:TemplateField HeaderText="Call Extension">
        <itemtemplate>
        <asp:Label ID="Label51" runat="server" Text='<%# Eval("CallExt") %>'>
        </itemtemplate>
        <edititemtemplate>
        <asp:TextBox ID="txtPostalAddress" runat="server" Text=' <%# Eval("CallExt") %>'>
        </edititemtemplate>
           
                                                             
        <asp:TemplateField HeaderText="Call Duration">
        <itemtemplate>
        <asp:Label ID="Label6" runat="server" Text='<%# Eval("CallDuration") %>'>
        </itemtemplate>
        <edititemtemplate>
        <asp:TextBox ID="txtResidentialAddress" runat="server" Text=' <%# Eval("CallDuration") %>'>
        </edititemtemplate>
            
                                
        <asp:TemplateField HeaderText="Amount">
        <itemtemplate>
        <asp:Label ID="Label7" runat="server" Text='<%# Eval("Amount") %>'>
        </itemtemplate>
        <edititemtemplate>
        <asp:TextBox ID="txtWebSite" runat="server" Text=' <%# Eval("Amount") %>'>
        </edititemtemplate>
       

        <asp:TemplateField HeaderText="tmpNewNam" Visible="False">
        <itemtemplate>
        <asp:Label ID="Label50" runat="server" Text='<%# Eval("tmpNewNam") %>'>
        </itemtemplate>
        <edititemtemplate>
        <asp:TextBox ID="txtIfOtherSpecify" runat="server" Text=' <%# Eval("tmpNewNam") %>'>
        </edititemtemplate>
            
 
                         </columns>
                            <emptydatatemplate>
                                <asp:RadioButton ID="RadioButton1" runat="server" />
                                 
                                <asp:RadioButton ID="RadioButton2" runat="server" />
                                <br />
                            </emptydatatemplate>
                            <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
Updated 13-Mar-16 23:23pm
v2
Comments
[no name] 14-Mar-16 5:19am    
When it is throwing exception and which line in your code-behind?
Member 12390137 14-Mar-16 6:56am    
Thanks Manas for response.I thought about the same thing, thought maybe i'm pointing to wrong cell number . I tried to change cells number until it give me this error. Specified argument was out of the range of valid values. surely is not about converting string to int or to datetime. Here is my query ("select CallID,NewNam,CallDate,CalledNo,CallExt,CallDuration,Amount,tmpNewNam from MCALLERS where UserName='lucasn' and CallDate>='01-Feb-2016' and CallDate<'01-Mar-2016' and Amount>0 order by CallDate") i'm sure it will give you some clarity. thanks in advance
Karthik_Mahalingam 14-Mar-16 6:57am    
validate either in Javascript or in Code behind.
post your code-behind code block.

1 solution

The error "Input string was not in a correct format." is pretty simple to describe: you are trying to convert a value to a datatype that it doesn't match. For example, you may be trying to convert a string to an integer, but the string contains non-numeric characters. OR you may be trying to convert a string to a DateTime, but the date in teh string is not in the same culture as the computer trying to convert it: if you POC is expected "mm/dd/yy" and you feed it "16/03/14" then it will fail.

Basically, it's your data, somewhere - and we have no access to that. So start by looking at what your code is processing, and what value syou try to convert it into. We can't do any of that for you, so it's time to start using the debugger and working it out!
 
Share this answer
 

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