Looking at your code, it's not obvious, but the use of the Equals method implies it wouldn't compile with the
==
operator:
if (LblURS =="New")
Presumably gave a compilation error.
With your reference to LblMN following teh same naming convention as LblURS, I would suspect that the compilation error made you change the "==" to use "Equals" - which will do a reference comparison between the two objects and is unlikely to succeed too well unless there is a direct assignment or the absolute string "New" to LblURS.
But I suspect there isn't, because LblURS is not a string - it's a Label control, just like LblMN.
So change your code back to "==" and use the Label.Text property instead:
if (LblMN.Text == "Incident")
{
if (LblURS.Text == "New")
{
LnkMSid.ToolTip="Incident is New";
GridView1.Rows[i].Cells[4].Attributes.Add("Style", "background: url(../Images/flag_blue.gif) no-repeat;");
}
else if (LblURS.Text == "Resolved")
{
LnkMSid.ToolTip="Incident has been Resolved";
GridView1.Rows[i].Cells[4].Attributes.Add("Style", "background: url(../Images/flag_orange.gif) no-repeat;");
}
else if (LblURS.Text == "Closed")
{
LnkMSid.ToolTip="Incident is Closed";
GridView1.Rows[i].Cells[4].Attributes.Add("Style", "background: url(../Images/flag_green.gif) no-repeat;");
}
else
{
LnkMSid.ToolTip="Incident is under progress";
GridView1.Rows[i].Cells[4].Attributes.Add("Style", "background: url(../Images/flag_red.gif) no-repeat;");
}
}
"OP Response with lots of code"
Wow! You don't believe in modular code then...:laugh:
Let's start off by making this a bit more readable, by modularising it and seeing what does what to what.
Create a switch statement to handle the LblMN.Text value:
KeyValuePair<string, string> kvp = new KeyVValuePair("???", "???");
switch(LblMN.Text.ToLower())
{
case "incident":
kvp = HandleIncident(LblURS.Text);
break;
case "problem":
kvp = HandleProblem(LblURS.Text);
break;
...
default:
throw new ApplicationException("Unknown MN code: " + LblMN.Text);
}
LnkMSid.ToolTip = kvp.Key;
GridView1.Rows[i].Cells[4].Attributes.Add("Style", "background: url(../Images/" + kvp.Value + ") no-repeat;");
Each of the methods holds (basically) the code from inside each of your if statements, and returns a new KeyValue Pair:
private KeyValuePair<string, string> HandleIncident(string urs)
{
...
return new KeyValuePair<string, string>("Incident has been Resolved", "flag_orange.gif");
...
}
This way, your loop becomes a lot clearer, and we can see at a glance what it going on.
(Normally, I'd create a class to return the pair of values, and it would be a good idea if you did, but that'll work - it's just a lot of typing and I don't want to confuse the issue with new classes.)