i am adding item from dropdown and their qty from textbox .i want when i add item and qty into gridview then their qty display into label which is outside of gridview.if item will same means that item exit in gridview and new adding item ,then both qty get
sum and display in label(lbitpqty0).
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Accroding to your description and codes,could you tell us where write the code you post.
Since you don't post more details,I create a demo.When I click the button,the textbox data will be added into gridview.At the same time,the value will display in the label.Then,you could sum the same Descriptionitem's qty.
If it's wrong,you could post your full codes and more details of your requirment to us.
if (DropDownList1.SelectedItem.Value != null)
{
int codeitem = Convert.ToInt32(DropDownList1.SelectedItem.Value.ToString());
string Descriptionitem = DropDownList1.SelectedItem.Text.ToString();
DataTable dtgridview = ViewState["dt"] as DataTable;
DataRow dr2 = dtgridview.NewRow();
bool ifExist = false;
foreach (DataRow dr in dtgridview.Rows)
{
if (dr["Prdno"].ToString() == TextBox1.Text.Trim())
{
ifExist = true;
break;
}
}
if (!ifExist)
{
dr2["Prdno"] = TextBox1.Text.Trim();
dr2["Codeitem"] = codeitem;
dr2["Descriptionitem"] = Descriptionitem;
dr2["Orderno"] = txtorderno.Text;
dr2["QTY"] = txtqty.Text;
dtgridview.Rows.Add(dr2);
// dtgridview.Rows.Add(dr2);
ViewState["dt"] = dtgridview;
GridView1.DataSource = dtgridview;
GridView1.DataBind();
lbOrderqty.Text= txtorderno.Text;
lbPackpqty.Text= txtqty.Text;
int qty =0;
foreach (GridViewRow gv in GridView1.Rows)
{
string x = ((Label)gv.FindControl("Descriptionitem")).Text;
if (DropDownList1.SelectedItem.Text == x)
{
int result= Convert.ToInt32(((Label)gv.FindControl("QTY")).Text);
qty += result;
}
lbitpqty0.Text = qty.ToString();
}
}
else
{
// this.lbgvck.Visible = true;
lbgv.Text = "Bale Already Added...";
}
}
Result:
Best regards,
Yijing Sun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
116 Points
274 Posts
Display gridview item wise qty in label(lbitpqty0) at the time of adding in gridview.
Jun 24, 2020 07:12 PM|akhterr|LINK
i am adding item from dropdown and their qty from textbox .i want when i add item and qty into gridview then their qty display into label which is outside of gridview.if item will same means that item exit in gridview and new adding item ,then both qty get sum and display in label(lbitpqty0).
here is my html
C# code adding item and qty into gridview
Participant
1253 Points
936 Posts
Re: Display gridview item wise qty in label(lbitpqty0) at the time of adding in gridview.
Jun 25, 2020 05:02 AM|yogyogi|LINK
You will have to do it with jQuery. See How to show sum of columns in the footer of the GridView with jQuery. To get some idea about the approach you need to follow.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Contributor
3730 Points
1427 Posts
Re: Display gridview item wise qty in label(lbitpqty0) at the time of adding in gridview.
Jun 25, 2020 06:36 AM|yij sun|LINK
Hi akhterr,
Accroding to your description and codes,could you tell us where write the code you post.
Since you don't post more details,I create a demo.When I click the button,the textbox data will be added into gridview.At the same time,the value will display in the label.Then,you could sum the same Descriptionitem's qty.
If it's wrong,you could post your full codes and more details of your requirment to us.
More detaisl,you could refer to below codes:
if (DropDownList1.SelectedItem.Value != null) { int codeitem = Convert.ToInt32(DropDownList1.SelectedItem.Value.ToString()); string Descriptionitem = DropDownList1.SelectedItem.Text.ToString(); DataTable dtgridview = ViewState["dt"] as DataTable; DataRow dr2 = dtgridview.NewRow(); bool ifExist = false; foreach (DataRow dr in dtgridview.Rows) { if (dr["Prdno"].ToString() == TextBox1.Text.Trim()) { ifExist = true; break; } } if (!ifExist) { dr2["Prdno"] = TextBox1.Text.Trim(); dr2["Codeitem"] = codeitem; dr2["Descriptionitem"] = Descriptionitem; dr2["Orderno"] = txtorderno.Text; dr2["QTY"] = txtqty.Text; dtgridview.Rows.Add(dr2); // dtgridview.Rows.Add(dr2); ViewState["dt"] = dtgridview; GridView1.DataSource = dtgridview; GridView1.DataBind(); lbOrderqty.Text= txtorderno.Text; lbPackpqty.Text= txtqty.Text; int qty =0; foreach (GridViewRow gv in GridView1.Rows) { string x = ((Label)gv.FindControl("Descriptionitem")).Text; if (DropDownList1.SelectedItem.Text == x) { int result= Convert.ToInt32(((Label)gv.FindControl("QTY")).Text); qty += result; } lbitpqty0.Text = qty.ToString(); } } else { // this.lbgvck.Visible = true; lbgv.Text = "Bale Already Added..."; } }
Result:
Best regards,
Yijing Sun