Hi,

Can get my code working fully. its just works partially.
Its a IF else statement, the value to the variable is to be read from a cell with intergers from 0 to 9, it works ok for value 4 = Open, but rest it not working.

int MST = Convert.ToInt32(Convert.ToInt32(DetailsView3.Rows[0].Cells[1].Text));

if (MST == 0)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}

else if (MST == 1)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
    DetailsView2.Rows[3].Cells[1].Text = "Order";
}
else if (MST == 2)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
    DetailsView2.Rows[3].Cells[1].Text = "Order";
}
else if (MST == 3)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
    DetailsView2.Rows[3].Cells[1].Text = "Open";
}
else if (MST == 4)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
    DetailsView2.Rows[3].Cells[1].Text = "Open";
}
else if (MST == 5)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}
else if (MST == 6)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}
else if (MST == 7)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}
else if (MST == 8)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}
else if (MST == 9)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}

Thank u.

Code seems to be fine.
Check that you are properly refering to the cell you needed.

One more thing if possible, write the statement into Switch Case statement. this suits much in this condition.

Thanks for your comments, but the cell is showing correct values, but my statement isn't reading except for the where MST=4.

Cant get the point.

How can i switch to "Switch Case"

Thank you.

NO 1 question is how u can understand which portion woeks fine/not. Cause all code block is same.

Another way is response.write MST in the ELSE block so that you can understand which value holds MST when if condition failed.

Can you give your sample code?

I have included in my post, if you are asking me?

I have tried its, seems its working from 4 towards still 8, rest have to check tomorow morning, as the above 0 to 4 will be appearing (its a time based service from 3rd party site, which give me the values)

Thanks again.

Add an else block & print mst value. hope everything will be clear.

Sorry,
I totally new on programming
(basically I am NetAdmin, and our dev is on leave), so excuse me.
I tried the debug print: System.Diagnostics.Debug.Print(MST);
But it gave me errors.
Today morning I check my status, the Cell were empty, no text, until Status changed to 4, and it showed "Open"

So please guide me, once again. Thanks

else if (MST == 9)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Closed";
}
else
{
Respnose.Write(MST.ToString());
// try to log the value of MST in a file
}

I tried it, but it gives error:
CS0103: The name 'MST' does not exist in the current context

OK JUST WRITE AFTER YOUR BELOW LINE:

int MST = Convert.ToInt32(Convert.ToInt32(DetailsView3.Rows[0].Cells[1].Text));

Respnose.Write(MST.ToString());

THEN TRY TO FIND OUT EXACTLY WHICH VALUE CONTAINS MST VALUE WHEN YOUR IF STATEMENT FAILED.

Thanks,

I applied it, but seems the the is no value in MST, where the status value is 0 (which is the "DetailsView3.Rows[0].Cells[1].Text" adding to MST), the first condition.
But it has no value when status is 0,1,2 & 2, but will start from value 4.

Now this is really confusing me. Does MST is some system variable or command etc, which is conflicting with me.

Thank you,

IF THERE IS NO VALUE I MEAN 0 THEN YOUR IF.. STATEMENT WILL BE FAILED. IT IS LOGICAL. NOW KEEP AN EYE ON DetailsView3.Rows[0].Cells[1].Text What you see when you get 0 another one is in which event you fill the mst value?

DetailsView3.Rows[0].Cells[1].Tex

Its show as the values from 0 to 9, and I should be getting the values for MST from this cell, but its collecting only after 4 till 9. the rest which is 0-3 its not collecting.

Honestly i didn't fnd any problem. please post the page full html code as well as cs code.

The attached are the HTML and CS codes.

JUST PASTE THE BELOW CODE BLOCK IN YOUR PAGE_LOAD EVENT. HERE I BIND DATASOURCES & YOUR IF..ELSE STAEMENT UNDER NOT ISPOSBACK METHOD. JUST FOLLOW THE BELOW WAY & LET ME KNOW THE STATUS:

if (!IsPostBack)
        {
            GridView1.DataBind();
            GridView2.DataBind();
            GridView3.DataBind();
            GridView4.DataBind();

            //REMOVED Other Codes....      

            //MARKET STATUS

            int MST = Convert.ToInt32(Convert.ToInt32(DetailsView3.Rows[0].Cells[1].Text));
            Response.Write("MST VALUE=" + MST.ToString());
            if (MST == 0)
            {
                DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
                DetailsView2.Rows[3].Cells[1].Text = "Closed";

            }

            else if (MST == 1)
            {
                DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
                DetailsView2.Rows[3].Cells[1].Text = "Order Acceptance";
            }
            else if (MST == 2)
            {

                DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
                DetailsView2.Rows[3].Cells[1].Text = "Pre-Auction";
            }
            else
            {
                DetailsView2.Rows[3].Cells[1].ForeColor = Color.Green;
                DetailsView2.Rows[3].Cells[1].Text = "Implement later";
            }
        }

It didnt help,

It show nothing, not even the text string "MST VALUE="

Its same state as before, only works after value is " 4 "

Does your DetailsView3 shows data? if not then populate it before if statement.

It will be better you can start a new thread cause in this thread i guess experts dont want to write.

So start a new thread like this.

Yes the DetailView3 show data, but its not poplating until the value 4.

And this is making me insane.

Ok. I will be starting a new Thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.