Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > Other Programming Languages
|
Other Programming Languages If you have a coding issue to discuss about another language that really isn't provided for in any other forum here (not ASP.NET C#, C++, VB, PHP, JavaScript, Python, Java, Perl, Applescript, XML or any of the other forum topics we have), post it here. Enough discussion on a language we don't have covered could prompt a new forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Other Programming Languages section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 14th, 2008, 09:46 AM
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
  #2 (permalink)  
Old February 14th, 2008, 10:14 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This question is much more intuitive then your previous question in the .NET forum.

Even if the gridview is the only control on the page, there are bound to be <tr> tags that do not have any associated properties. I assume that is why you are recieving this error.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old February 14th, 2008, 11:12 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've figured out a bit more since the post in the .net forum :D

So do I have to then only apply the changeColour to the <tr tags that are relevant through my for loop?


Reply With Quote
  #4 (permalink)  
Old February 14th, 2008, 11:23 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Quote:
quote:Originally posted by Andrew.Berry


So do I have to then only apply the changeColour to the <tr tags that are relevant through my for loop?
Well I can't really answer that, it isn't my application ;] Presumeably you will only want to apply your style to the rows that you want to blink i suppose.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #5 (permalink)  
Old February 14th, 2008, 11:50 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yep, it's the ones that should be picked up with:

Code:
function StartFlashing(){
 var rowArray=document.getElementsByTagName('tr');
    for (i=0;i<rowArray.length;i++)
    {
        if (rowArray[i].getAttribute('flash')=='true')
        {
            changeColour(rowArray[i].id);
        }
    }
It's only if the attribute flash is true that it calls the changeColour method - which is where it's going wrong.

I think that changeColour(rowArray[i].id); that isn't working right.

Reply With Quote
  #6 (permalink)  
Old February 14th, 2008, 12:35 PM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Update:

New Code:
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]);
 }
 }

}

function changeColour(element) {
 var interval = 1000;
 var colour1 = "#ff0000";
 var colour2 = "#000000";
 if (document.getElementById) {
 element.style.color = (element.style.color == colour1) ? colour2 : colour1;
 setTimeout("changeColour('" + element + "')", interval);
 }
}
As I was having trouble passing my elementid in, instead I thought i'd pass the element.

Now the text will begin to flash (by turning red) but on the turn to colour2, it throws the following error: Style is null or not an object. Any clues?



Reply With Quote
  #7 (permalink)  
Old February 14th, 2008, 05:26 PM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Managed to get it working now :)

Will post code when i'm back at work tomorrow.

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Making Text Flash in a gridview Andrew.Berry ASP.NET 2.0 Basics 2 February 14th, 2008 09:57 AM
Making text in a gridview flash on certain event Andrew.Berry ASP.NET 2.0 Basics 2 January 12th, 2008 12:14 PM
javascript blink in innerHTML crmpicco Javascript How-To 8 April 3rd, 2006 06:38 AM
Making a text object writable sureshbabu Crystal Reports 0 December 16th, 2004 01:29 AM
Making a label blink levinll VB How-To 2 June 23rd, 2004 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.