Click here to Skip to main content
14,691,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 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();


              }


          }


it's wrong subtract 1000 every column.
Posted
Updated 12-Dec-13 22:34pm
v6
Comments
   
What do you mean "how"? By writing some code. Any particular concerns? What have you tried so far?
So far, it does not require expert's help, it's just some work to be done.
—SA
JoCodes 13-Dec-13 3:20am
   
Post your Gridview markup code too...
breaker-code 13-Dec-13 3:27am
   
DataTable dt = new DataTable();
String ReceptNUm = txtinvoice.Text.ToString().Trim();
dt = RE.getinvoicedetailsINV(ReceptNUm);

if (dt != null && dt.Rows.Count > 0)
{
Cusinvoicegrid.DataSource = dt;
Cusinvoicegrid.DataBind();
dt.Clear();
btn_Cash_Ok.Visible = true;


}
JoCodes 13-Dec-13 3:31am
   
Html Markup Code for the gridview
breaker-code 13-Dec-13 3:34am
   
<asp:GridView ID="Cusinvoicegrid" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3"
Width="100%" onselectedindexchanged="Cusinvoicegrid_SelectedIndexChanged">
<columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="InvoiceNo" HeaderText="InvoiceNo" />
<asp:BoundField DataField="InvAmtLKR" HeaderText="InvAmt" />
<asp:BoundField DataField="TotalDuePaid" HeaderText="Last Payment" />
<asp:BoundField DataField="TotalPaid" HeaderText="Out Standing" />
<asp:TemplateField>
<itemtemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />



<footerstyle backcolor="White" forecolor="#000066">
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<rowstyle forecolor="#000066">
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#007DBB">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#00547E">
JoCodes 13-Dec-13 3:49am
   
Are you trying to do calculations as per any conditions?If so try the calculation code in the Gridview Rowdatabound event .
your code contains a check for checkbox selection too?

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())) %>'


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
   
v2

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