I need to enter the Product details from textbox to gridview row.
If the same Product already in gridview, just update the quantity and rate.
else enter the new row.
the code I have used:
- foreach (DataGridViewRow row1 in dgvmaingrid.Rows)
- {
- if (row1.Cells["PNAME"].Value.Equals(txtProdsearch.Text.Trim()) && row1.Cells["DESC"].Value.Equals(txtDesc.Text.Trim()))
- {
- row1.Cells["QTY1"].Value = (double.Parse(row1.Cells["QTY1"].Value.ToString()) + double.Parse(txtQty.Text));
- row1.Cells["NETAMT"].Value = Convert.ToDecimal(String.Format("{0:0.00}", Convert.ToDecimal((double.Parse(row1.Cells["NETAMT"].Value.ToString()) + double.Parse(txtNetPrice.Text))))).ToString();
- return;
- }
- else if (row1.Cells["PNAME"].Value.ToString() != (txtProdsearch.Text.Trim()) && row1.Cells["DESC"].Value.ToString() != (txtDesc.Text.Trim()))
- {
- dgvmaingrid.Rows.Add();
- snoadd = snoadd + 1;
- row = dgvmaingrid.RowCount - 1;
- dgvmaingrid.Rows[row].Cells["sno"].Value = snoadd;
- dgvmaingrid.Rows[row].Cells["PNAME"].Value = txtProdsearch.Text;
- dgvmaingrid.Rows[row].Cells["DESC"].Value = txtDesc.Text;
- dgvmaingrid.Rows[row].Cells["QTY1"].Value = txtQty.Text;
- dgvmaingrid.Rows[row].Cells["RATE1"].Value = txtUPrice.Text;
- double neti = double.Parse(txtNetPrice.Text);
- dgvmaingrid.Rows[row].Cells["NETAMT"].Value = Convert.ToDecimal(String.Format("{0:0.00}", Convert.ToDecimal(neti))).ToString();
- return;
- }
- }
Thank you in advance...



Nanddeep NachanRank #38 · 35.2K reputationPosted Jul 9, 2018, 2:08 AM EDT
Rajasekaran Bose64 reputationPosted Jul 9, 2018, 2:38 AM EDT
Nanddeep NachanRank #38 · 35.2K reputationPosted Jul 9, 2018, 2:40 AM EDT
Rajasekaran Bose64 reputationPosted Jul 9, 2018, 2:43 AM EDT
Nanddeep NachanRank #38 · 35.2K reputationPosted Jul 9, 2018, 2:45 AM EDT