You need to find the
price
label and convert that to
double
. Also, assign the
sum
to
TextBox
after the loop. Update your code as below.
protected void Button3_Click(object sender, EventArgs e)
{
double sum = 0;
foreach (GridViewRow gvr in gvchekvalue.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("chkItem");
if (cb.Checked)
{
Label lblPrice = (Label)gvr.FindControl("Label1");
double amount = Convert.ToDouble(lblPrice.Text);
sum += amount;
}
}
txtamount.Text = sum.ToString();
}