Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello, I have a problem with Combine two condition down below, I try many things to use that two condition together but it didn't work, if someone can help me or have some way to solve this I will be hopeful



Thanks..

What I have tried:

C#
if (e.Row.RowType == DataControlRowType.DataRow)
{
	//put your control name here to get and then check for your value
	Label lbl = e.Row.FindControl("Label17") as Label;

	if (lbl.Text == "ملغي Cancled ")
	{
	   e.Row.BackColor = Color.Red && Amount == 0; // -----> Problem is here
		return; //will stop here
	}
}
Posted
Updated 6-Aug-17 23:47pm
v2
Comments
Graeme_Grant 7-Aug-17 5:41am    
Yes, that is a syntax error. What are you attempting to do on the problematic line?

The problem is that "&&" is a boolan operation, and so is "==" - but no combination of operator precedence ends up with the same types on each side of both opertors:
(Color.Red && Amount) == 0
is comparing a bool to an int.
Color.Red && (Amount == 0)
is comparing a Color to a bool.
So the compile complains.
I suspect you meant to use the binary AND:
(Color.Red & Amount) == 0
But without knowing your project, I can't really tell.
 
Share this answer
 
Comments
Learn.net37 7-Aug-17 5:46am    
ok the code for gridview when label = "ملغي Canceled

make the row back colour = red and (amount) that label bind in database = 0 so it will not be calculated and this is code for databound


int Amount = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{





if (e.Row.RowType == DataControlRowType.DataRow)
{



//put your control name here to get and then check for your value
Label lbl = e.Row.FindControl("Label17") as Label;

if (lbl.Text == "ملغي Cancled ")
{
e.Row.BackColor = (Color.Red & Amount) == 0;
return; //will stop here
}




}
if (e.Row.RowType == DataControlRowType.DataRow)
{
Amount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Spare1"));

}
// Display totals in the gridview footer
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[9].Text = " Grand_Total: " + Amount.ToString("#,##0") + " " + "SAR ";
e.Row.Cells[9].Font.Bold = true;




}



}
Patrice T 7-Aug-17 5:49am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Do you mean:
C#
if (e.Row.RowType == DataControlRowType.DataRow)
{
	//put your control name here to get and then check for your value
	Label lbl = e.Row.FindControl("Label17") as Label;
 
	if (lbl.Text == "ملغي Cancled ")
	{
           e.Row.BackColor = Color.Red;
           Amount = 0;
           return;
	}
}
 
Share this answer
 
v2
Comments
OriginalGriff 7-Aug-17 5:54am    
What is "Amount == 0;" supposed to do?
Graeme_Grant 7-Aug-17 6:21am    
True ... I should have corrected that also... d-d-d-done...
Learn.net37 7-Aug-17 6:39am    
its supposed to make the value 0 , mean it's not calculate with other records
OriginalGriff 7-Aug-17 6:40am    
Read it again: "==" is a logical operator, not an assignment operator. That's "="
Graeme_Grant 7-Aug-17 6:47am    
Yes, Amount = 0; assigns the value 0 to Amount.
C#
e.Row.BackColor = Color.Red && Amount == 0; // -----> Problem is here

Yes, this code is meaningless, so there is no possible correction because you didn't told us what it is supposed to do.
Quote:<
/div>I have a problem with Combine two condition down below

Color.Red is not a condition.
Explain what you want to do.
[Update]
This have no meaning either:
C#
e.Row.BackColor = (Color.Red & Amount) == 0;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900