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.

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.

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.

The attached are the HTML and CS codes.

Attachments
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        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.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 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 = "Forward Entry";
}
else if (MST == 6)
{
    DetailsView2.Rows[3].Cells[1].ForeColor = Color.Red;
    DetailsView2.Rows[3].Cells[1].Text = "Forward Trading";
}
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";
}

// MARKET SUMMARY ADDITIONS ENDS


}
else
{
    //Response.Write(MST.ToString());
    // try to log the value of MST in a file
}


    }
}
<ContentTemplate>
                <table style="width: 330px">
                    <tr>
                        <td style="width: 55%">
                          <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="3" BorderColor="WhiteSmoke" BackColor="WhiteSmoke"
                            DataSourceID="MktSum" ForeColor="#333333" GridLines="None" Height="124px" Font-Size="10pt" CellSpacing="1" Width="175px">
                            <Fields>
                                <asp:BoundField DataField="Price Index" HeaderText="Price Index" ReadOnly="True" SortExpression="Price Index" NullDisplayText="0" DataFormatString="{0:##,##}" HtmlEncode="False">
                                    <ControlStyle Width="80px" />
                                    <ItemStyle Width="60px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="Change" HeaderText="Change" ReadOnly="True" SortExpression="Change" NullDisplayText="0" >
                                    <ControlStyle Width="80px" />
                                    <ItemStyle Width="60px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="Wieghted Index" HeaderText="Weighted Index"  SortExpression="Wieghted Index" NullDisplayText="0" >
                                    <ControlStyle Width="80px" />
                                    <ItemStyle Width="60px" />
                                    <HeaderStyle Font-Size="9pt" />
                                </asp:BoundField>
                                <asp:BoundField DataField="ChangeW" HeaderText="ChangeW" ReadOnly="True"  SortExpression="ChangeW" NullDisplayText="0" >
                                    <ControlStyle Width="80px" />
                                    <ItemStyle Width="60px" />
                                </asp:BoundField>
                            </Fields>
                          <CommandRowStyle Font-Bold="True" BorderColor="WhiteSmoke" BorderWidth="1px" />
                            <PagerStyle ForeColor="White" HorizontalAlign="Center" />
                            <FieldHeaderStyle Font-Bold="True" />
                            <EditRowStyle BackColor="#2461BF" />
                            <RowStyle BackColor="#ECECEC" Font-Names="Arial,Helvetica,sans-serif;" Font-Size="10pt" />
                            <HeaderStyle Height="8px" HorizontalAlign="Left" Font-Names="Arial,Helvetica,sans-serif;" Font-Size="10pt" ForeColor="White" Font-Bold="True"  />
                            <AlternatingRowStyle BackColor="#F6F3E2" />
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                         </asp:DetailsView>
                        </td>
                        <td style="width: 50%">
                           <asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" CellPadding="0" BorderColor="WhiteSmoke" BackColor="WhiteSmoke"
                    DataSourceID="MktSum" ForeColor="#333333" GridLines="None" Height="124px" Width="100%" Font-Size="10pt" BorderStyle="None" CellSpacing="1">
                                <Fields>
                        <asp:BoundField DataField="Volume" HeaderText="Volume" ReadOnly="True" SortExpression="Volume" NullDisplayText="0"  DataFormatString="{0:##,##}" HtmlEncode="False"  >
                            <ControlStyle Width="50px" />
                            <ItemStyle Width="80px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Value" HeaderText="Value" ReadOnly="True" SortExpression="Value" NullDisplayText="0"  DataFormatString="{0:##,##}" HtmlEncode="False" >
                            <ControlStyle Width="50px" />
                            <ItemStyle Width="80px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Deals" HeaderText="Deals" ReadOnly="True" SortExpression="Deals" NullDisplayText="0"  DataFormatString="{0:##,##}" HtmlEncode="False" >
                            <ControlStyle Width="50px" />
                            <ItemStyle Width="80px" />
                        </asp:BoundField>
                                    <asp:TemplateField HeaderText="Status">
                                    </asp:TemplateField>
                                </Fields>
                    <CommandRowStyle BackColor="#587BB7" Font-Bold="True" ForeColor="White" BorderColor="WhiteSmoke" BorderStyle="Solid" BorderWidth="1px" />
                    <PagerStyle BackColor="#5D7B9D" ForeColor="White" HorizontalAlign="Center" />
                    <FieldHeaderStyle  Font-Bold="True" />
                    <EditRowStyle BackColor="#2461BF" />
                    <RowStyle  BackColor="#ECECEC"  Font-Names="Arial,Helvetica,sans-serif;" Font-Size="10pt" />
                    <HeaderStyle Height="8px" HorizontalAlign="Left" BackColor="#003399" Font-Names="Arial,Helvetica,sans-serif;" Font-Size="10pt" ForeColor="White" Font-Bold="True" />
                     <AlternatingRowStyle BackColor="#F6F3E2" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            </asp:DetailsView>
                        </td>
                    </tr>
                </table>
                <asp:DetailsView ID="DetailsView3" runat="server" AutoGenerateRows="False" DataSourceID="MktSum"
                    Font-Size="7pt" Height="13px" Width="125px">
                    <Fields>
                        <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" >
                         <ControlStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                         <ItemStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" ForeColor="Black" />
                         <HeaderStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                        </asp:BoundField>
                    </Fields>
                    <FooterStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                    <CommandRowStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                    <EmptyDataRowStyle BackColor="#ECECEC" BorderColor="#ECECEC" />
                    <EditRowStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                    <RowStyle BackColor="LightGray"  BorderColor="#ECECEC" ForeColor="#ECECEC" />
                    <PagerStyle BackColor="#ECECEC" BorderColor="#ECECEC" />
                    <FieldHeaderStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                    <HeaderStyle BackColor="#ECECEC" BorderColor="#ECECEC" BorderStyle="None" />
                     <AlternatingRowStyle BackColor="#F6F3E2" />
                </asp:DetailsView>
            
        </ContentTemplate>

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.

This article has been dead for over six months. Start a new discussion instead.