Gridview内部计算 [英] Gridview inside Calculation

查看:54
本文介绍了Gridview内部计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gridview Display Customer Inv number and Amount.cutomer paid same amount.i insert this amountTextBox1.i want to automatically Calculate  subtract and subtract inside the Gridview. 
 
This is customer payment Gridview 

Payment Amount:  TextBox1.text(1000.00)

           INV        INVamount     Payment      OutStanding

Select      1         250.00         250.00        000.00

 
Select      2         1750.00        750.00       1000.00


  Customer paid 1000.00, INV 1 amount 250.00 this payment close and NO OutStanding and
  balance is 750 and this 750.00 amount subtract to INV 2 and OutStanding 1000.00.

How to do it??any one can help me





i try此代码





i try This code

//bind datagrid

          for (int i = 0; i < Cusinvoicegrid.Rows.Count; i++)
          {
              if ((Cusinvoicegrid.Rows[i].Cells[5].FindControl("CheckBox1") as CheckBox).Checked == true)
              {
                  if (Session["dt1"] != null) dt1 = (DataTable)Session["dt1"];
                  DataRow dr = dt1.NewRow();
                  dr["InvoiceNO"] = Cusinvoicegrid.Rows[i].Cells[1].Text;//1
                  dr["Invamount"] = Cusinvoicegrid.Rows[i].Cells[2].Text;//2

                  Label1.Text = Cusinvoicegrid.Rows[i].Cells[2].Text;//2
                  decimal a = Convert.ToDecimal(Label1.Text);
                  decimal b = Convert.ToDecimal(txtpaymentDetails0.Text);
                  decimal c = a - b;
                  Label2.Text = Convert.ToString(c);

                  dr["Lastpayment"] = txtpaymentDetails0.Text;//3
                  dr["outstanding"] = Label2.Text;//4


                  dt1.Rows.Add(dr);


                  Cusinvoicegrid0.DataSource = dt1;
                  Cusinvoicegrid0.DataBind();


              }


          }





错误每列减去1000。



it's wrong subtract 1000 every column.

推荐答案

计算的一种方法是在Gridview中将Boundfield更改为Templatefield,如下所示



One way to do the calculation is changing the Boundfield to Templatefield in Gridview do as below

Text='<%# (Convert.ToDecimal(Eval("InVamount")) - Convert.ToDecimal(Eval("payment").ToString())) %>'





另一种在Gridview的RowDataBound事件中处理此问题的方法。 />


希望这有助于...



And the other way to handle this in the RowDataBound event of the Gridview .

Hope this helps...


for (int i = 0; i < dataGridView1.Rows.Count; i++)
               {
                   Total += Convert.ToInt16(dataGridView1.Rows[i].Cells["amount"].Value);

                 take your value in any label or textbox // txtearning.Text = Total.ToString();

               }
               for (int i = 0; i < dataGridView2.Rows.Count; i++)
               {
                   Total1 += Convert.ToInt16(dataGridView2.Rows[i].Cells["amount"].Value);

                  take your value in any label or text// txtdeduction.Text = Total1.ToString();
               }
               int a = Convert.ToInt32(txtearning.Text);
               int b = Convert.ToInt32(txtdeduction.Text);

              take your value in any textbox or label and do it //txtnsalary.Text = (a - b).ToString();





//这些上面的代码用方法编写并在你想要的地方调用这个方法



//these above code written in method and call this method where u want


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

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