protected void ChkPayment_CheckChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in grvPaymentList.Rows)
{
var Selection = gvrow.FindControl("ChkSelected") as CheckBox;
decimal Total=0;
decimal abc=0;
if (Selection.Checked)
{
var moviePrice = gvrow.FindControl("MoviePrice") as Label ;
abc = Convert.ToDecimal(moviePrice.Text);
}
Total = Total + abc;
lblAmount.Text = Total.ToString();
}
}
Check The CheckBox and total the amount in label. How can I achieved it due to I am getting error for convert from string to decimal.
2 things you need to fix here:
EDIT: The Total variable needs to be declared outside the loop. What happens now is that you declare the variable inside the loop, so it gets reset during each iteration of the loop.