Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
C#
if (LblMN.Text == "Incident")
          {

              if (LblURS.Equals("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.Equals("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.Equals("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;");
              }
          }



Above is the code Can you tell what is wrong with it .. it execute, but straight goes to Else Statement whether the conditon true or false

and leave all the above else if staement .....
Posted
Updated 26-Sep-13 22:32pm
v2
Comments
CPallini 27-Sep-13 4:31am    
Are you sure LblURS.Text matches exactly one of the alternatives above the else clause (please note: Equals is case-sensitive)?
Thomas ktg 27-Sep-13 4:41am    
I would suggest you make the LblURS.Text to Lower case and compare the values with the Lower
case as if (LblMN.Text.ToLower() == "incident") either you make as lower or upper. But both should in same case.
hira_1 27-Sep-13 5:11am    
LblbMn actually is id it should be written as mentioned either in upper or lower
Pheonyx 27-Sep-13 5:20am    
Which if statement(s) is it skipping? Is it getting to the inner ifs which compare "LblURS" or is it skipping to an else relating to "LblMN" ? Also, when you step through the code, what values are being stored in "LblURS" ? I'm guessing it is a label control? if so, it should be LblURS.Text.Equals and not LblURS.Equals becuase a string will never be equal to a label control.
hira_1 27-Sep-13 5:32am    
let me tel you Lbl is Actualy ALabel field :
LblUrs is actualy an id for column "UserRequestQuery" LblMN For Column "ModuleName"
Actually this code checks that
If(ModuleName is equal to value "incident")
{
and also if (UserRequestQueryColumn cloumn contain text "New")
then it will set following image or color to cell {4}
}

now you got it....

what it is right now doing
Directly get skipped to
this Satatement
else
{
LnkMSid.ToolTip="Incident is under progress";
GridView1.Rows[i].Cells[4].Attributes.Add("Style", "background: url(../Images/flag_red.gif) no-repeat;");
}
Whether condition true or false

Looking at your code, it's not obvious, but the use of the Equals method implies it wouldn't compile with the == operator:
C#
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:
C#
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:
C#
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:
C#
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.)
 
Share this answer
 
v2
Comments
hira_1 27-Sep-13 5:42am    
Ok i'll try this
CPallini 27-Sep-13 5:44am    
Wow, good catch, indeed. My 5.
hira_1 27-Sep-13 6:10am    
I tried but i did'nt work still the same... :(
OriginalGriff 27-Sep-13 6:15am    
OK - so you need to look at exactly what is going on. Have you tried putting a breakpoint on the
if (LblMN.Text == "Incident")
line and stepping through the method watching what it going on?
What exact value do you have in LblURS.Text?
hira_1 27-Sep-13 6:20am    
Yes i did after debugging i come to know the issue :)
Better use

C#
if (LblURS.ToUpper.Equals("NEW"))<big></big>
 
Share this answer
 
Try to use following syntax. Hope it will solve your issues.
C#
if (LblURS.Text.ToUpper().Equals("NEW"))
{
........................
..........
...........
..........
      {
 
Share this answer
 
v2
Comments
hira_1 1-Oct-13 6:06am    
Thanbk you all for your help ,, but still this error not getting resolved ... :(
hira_1 1-Oct-13 6:22am    
Purpose of this code was to print image in the cell of grid depending on the conditio of of two other cell in the grid.....

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