View Single Post
  #1 (permalink)  
Old February 14th, 2008, 09:46 AM
Andrew.Berry Andrew.Berry is offline
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Making text blink in a gridview with Javascript.

Hi all,

If you have been over to the ASP.net 2 beginner thread, you will have seen that I have been trying to make text flash in a gridview dependant on certain requirements.

Now i'm nearly there (i hope!). What I have done is in my c# code behind I have done the following:

Code:
if (status.Contains("Artwork"))
            {
                e.Row.BackColor = System.Drawing.Color.Green;
                e.Row.ForeColor = System.Drawing.Color.White;

                if (Difference < limit)
                {
                    e.Row.Style["font-weight"] = "bold";
                    e.Row.Attributes.Add("flash", "true");

                }
            }

            else if (status.Contains("Printing"))
                {
                    e.Row.BackColor = System.Drawing.Color.Yellow;
                    e.Row.ForeColor = System.Drawing.Color.Black;

                    if (Difference < limit)
                    {
                        e.Row.Style["font-weight"] = "bold";
                        e.Row.Attributes.Add("flash", "true");
                    }
                }

            else if (status.Contains("Finishing"))
                {
                    e.Row.BackColor = System.Drawing.Color.Red;
                    e.Row.ForeColor = System.Drawing.Color.White;

                    if (Difference < limit)
                    {
                        e.Row.Style["font-weight"] = "bold";
                        e.Row.Attributes.Add("flash", "true");
                    }
                }

            else if (status.Contains("Vutek"))
                {
                    e.Row.BackColor = System.Drawing.Color.Blue;
                    e.Row.ForeColor = System.Drawing.Color.White;

                    if (Difference < limit)
                    {
                        e.Row.Style["font-weight"] = "bold";
                        e.Row.Attributes.Add("flash", "true");
                    }
                }

            else
                {
                    e.Row.BackColor = System.Drawing.Color.Gray;
                    e.Row.ForeColor = System.Drawing.Color.White;
                    e.Row.Attributes.Add("flash", "true");

                    if (Difference < limit)
                    {
                        e.Row.Style["font-weight"] = "bold";
                        e.Row.Attributes.Add("flash", "true");
                    }

                }//end else


The main bit to look at is the e.Row.Attributes bit. This attribute tells me if I need to make the text blink or not.

Now in my aspx page I have <body on load=startup();> which does the following

Code:
function startup(){
    StartFlashing()
}

function StartFlashing(){
 var rowArray=document.getElementsByTagName('tr');
    for (i=0;i<rowArray.length;i++)
    {
        if (rowArray[i].getAttribute('flash')=='true')
        {
            changeColour(rowArray[i].id);
        }
    }

}

function changeColour(elementId) {
    var interval = 1000;
    var colour1 = "#ff0000";
    var colour2 = "#000000";
    if (document.getElementById) {
        var element = document.getElementById(elementId);
        element.style.color = (element.style.color == colour1) ? colour2 : colour1;
        setTimeout("changeColour('" + elementId + "')", interval);
    }
}
Now when I run this, I am getting the following error:

element has no properties

[Break on this error] element.style.color = (element.style.color == colour1) ? colour2 : colou...

Any thoughts why my element has null?

Reply With Quote