Hi all,

I have a problem with manipulating gridview with a textbox inside the same form. My requirement is I have a gridview
where cell[1] is quantity, cell[2] is a boundfield which shows the rate and cell[3] is discount and i have a textbox
control outside gridview in th form where the user would enter a discount percentage which is to be shown in the
gridview cell[3] and finally the gridview cell[4] must display the net value after discount.

Thank you all please help

Is Discount same for all items (for all the rows in gridview)?
This is an important question so code knows what to update - or a sinlge row or all the rows.

just use DataGridView_CellLeave Event And Put that event for that discount column

you can get the discount column by simply Column Index and make ur calculation inside with the IF condition that the required column name is that discount ...

Depends on what he wants. He 1st needs to answer on my questions.

Hi all
thank you for replying user has to check the checkbox or click a edit button in the grodview to enter the dicount amount
and i have used c# as my code behind
thank you

Use CellContentClick event to detect buttonClicked:

private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
   if(e.ColumnIndex == 3) //code bellow will only work if 4th cell will be clicked (column with index 3 - as you said!)
      if(textBoxDiscount.Text.Length > 0)
         int quantity = int.Parse(dataGridView1[1, datagridview1.CurrentCell.RowIndex].Value.ToString());
         decimal rate = decimal.Parse(dataGridView1[2, datagridview1.CurrentCell.RowIndex].Value.ToString());
         int discount = int.Parse(textBoxDiscount.Text);
         decimal total = Convert.ToDecimal(quantity) * rate;
         total = (total * (100 - Convert.ToDecimal(discount)) / 100;

         //write to 4th cell the total calculated:
         dataGridView1[3, datagridview1.CurrentCell.RowIndex].Value = total.ToString("c"); //with your currency sign (€ or $,...)
   }     MessageBox.Show("Please enter the dicount to do the calculation!");

Hope ut helps mate,
tell me if the formula is the right one.

Hi Mitja,
But unfortunately am trying to create a web application sorry for not specifying the details clearly in the previous post
and your formula works perfectly on a windows application and if you can please help me with a code that would work
on a web application. Even javascript could be useful. Thanks for being kind with quick replies and code.
Thank you Mitja

really sorry mate, but I dont do web apps :( (yet).
Wait, someone will come to help you out!

Thank you anyway mate for trying hard to help me out and it gets complicated with web application