Answered by:
How To Remove Negative Values From My Code

Question
-
User-807418713 posted
Hello
This is my code in A1 Label It wil have negative value as well i want to skip negative value and add only postive value
Label LPrice234 = (Label)e.Row.FindControl("A1"); decimal PiecesTotal234 = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")); if (e.Row.RowIndex == 0) { TPcs234 = PiecesTotal234; } else { TPcs234 += PiecesTotal234; } LPrice234.Text = PiecesTotal234.ToString();
how to do so
Thanking You
Wednesday, December 11, 2019 4:13 AM
Answers
-
User-719153870 posted
Hi Gopi.MCA,
As we can see from your code, the value of your Label is set like:
LPrice234.Text = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")).ToString();
, is that right? It has nothing to do withTPcs234
?If so, why not use an if condition? please refer to below code:
Label LPrice234 = (Label)e.Row.FindControl("A1"); decimal PiecesTotal234 = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")); if (e.Row.RowIndex == 0) { TPcs234 = PiecesTotal234; } else { TPcs234 += PiecesTotal234; } if(PiecesTotal234 >= 0) { LPrice234.Text = PiecesTotal234.ToString(); }
If i misunderstood anything, please feel free to tell.
Best Regard,
Yang Shen
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 11, 2019 5:47 AM -
User-1716253493 posted
Label LPrice234 = (Label)e.Row.FindControl("A1"); decimal PiecesTotal234 = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")); if(PiecesTotal234>0) { if (e.Row.RowIndex == 0) { TPcs234 = PiecesTotal234; } else { TPcs234 += PiecesTotal234; } } LPrice234.Text = PiecesTotal234.ToString();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 11, 2019 6:55 AM
All replies
-
User-719153870 posted
Hi Gopi.MCA,
As we can see from your code, the value of your Label is set like:
LPrice234.Text = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")).ToString();
, is that right? It has nothing to do withTPcs234
?If so, why not use an if condition? please refer to below code:
Label LPrice234 = (Label)e.Row.FindControl("A1"); decimal PiecesTotal234 = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")); if (e.Row.RowIndex == 0) { TPcs234 = PiecesTotal234; } else { TPcs234 += PiecesTotal234; } if(PiecesTotal234 >= 0) { LPrice234.Text = PiecesTotal234.ToString(); }
If i misunderstood anything, please feel free to tell.
Best Regard,
Yang Shen
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 11, 2019 5:47 AM -
User-1716253493 posted
Label LPrice234 = (Label)e.Row.FindControl("A1"); decimal PiecesTotal234 = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Process_Loss_SqftNew")); if(PiecesTotal234>0) { if (e.Row.RowIndex == 0) { TPcs234 = PiecesTotal234; } else { TPcs234 += PiecesTotal234; } } LPrice234.Text = PiecesTotal234.ToString();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 11, 2019 6:55 AM