TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajasekaran Bose
NA
66
511
Insert or Update Gridview value with textbox value
Jul 9 2018 5:37 AM
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
;
}
}
but this code not working properly. I need help.
Thank you in advance...
Reply
Answers (
9
)
DataGridview unbound data imported from excel
print two copies in single sheet same data