嗨伙计。请帮忙 [英] Hi folks. Please help

查看:68
本文介绍了嗨伙计。请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Checkbox1的gridview,其余的是列,但重要的是 Amount Column.if我选中了3个复选框,它必须根据选中的复选框计算Amount。任何想法请帮助



我尝试过的事情:



我的gridview



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

<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

推荐答案

错误输入字符串格式不正确。很容易描述:您正在尝试将值转换为不匹配的数据类型。例如,您可能尝试将字符串转换为整数,但该字符串包含非数字字符。或者您可能正在尝试将字符串转换为DateTime,但是字符串中的日期与尝试转换它的计算机不在同一文化中:如果您希望POC为mm / dd / yy并且您将其输入 2014年3月16日然后它会失败。



基本上,这是你的数据,某处 - 我们无法访问它。首先看一下你的代码正在处理什么,以及你尝试将它转换成什么值。我们不能为您做任何事情,所以是时候开始使用调试器并进行解决了!
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!


这篇关于嗨伙计。请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆