I am transferring data from one GridView to another GridView, after transferring data then GridView is not displaying correctly Column sum.
Decimal DDQTY = 0;
Decimal DDWeight = 0;
protected void GVballist_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblDQ = (Label)e.Row.FindControl("Qty");
DDQTY += Convert.ToDecimal(lblDQ.Text);
Label lblDWT = (Label)e.Row.FindControl("BWeight");
DDWeight += Convert.ToDecimal(lblDWT.Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblQTotal");
lbl.Text = DDQTY.ToString();
Label lbl1 = (Label)e.Row.FindControl("lblWTotal");
lbl1.Text = DDWeight.ToString();
}
}
when I am selecting multiple row with checkbox in GridView, then update database table with a ID.
after updating table in database, then query executed and fetch data from database again into GridView, then it is not calculating column sum properly.
protected void btn_Trfer_Click(object sender, EventArgs e)
{
if (lbinvid.Text == "")
{
Response.Write("<script>alert('Please Generate Invoice ID.')</script>");
}
else
{
foreach (GridViewRow row in GVballist.Rows)
{
if ((row.FindControl("CheckBox1") as CheckBox).Checked)
{
int id = Convert.ToInt32((row.FindControl("hfBID1") as HiddenField).Value);
using (SqlCommand cmd = new SqlCommand("Sp_Ret_DisBale_BB_INv", con))
{
cmd.Parameters.AddWithValue("@Action", "Update_Invoice");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.AddWithValue("@Inv_ID", lbinvid.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lbmsg.Text = "Transfer Successfully.";
lopadgvtranfer();
}
}
}
}