We help IT Professionals succeed at work.

GRIDVIEW CELL BLINKING BEHIND CODE

BOEING39
BOEING39 asked
on
I have the following code example that I would like to insert into the attached code behind to make colum [2] blink based on the criteria in column [15] being either "MCO" or "MMCO".  The below code sniplet is an example for a timestamp.   Need assistance in applying to the attached code.


public void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
 {
 
 if (e.Row.RowType == DataControlRowType.DataRow)
 {

 // cell[2] postion of column to BLINK, cell position based on criteria to BLINK = [15] when = "MCO" or "MMCO"

 if (Convert.ToDateTime(e.Row.Cells[3].Text) > DateTime.Now)
 {
 e.Row.Style.Add("text-decoration", "blink");
 e.Row.Style.Add("color", "red");
 }
 
 }
Home1All.aspx.cs
Comment
Watch Question

Obadiah ChristopherDeveloper User Interface
CERTIFIED EXPERT

Commented:
So what's the issue here?

Is this what you are looking for?

if (e.Row.Cells[15].Text == "MCO" || e.Row.Cells[15].Text == "MMCO")
            {
e.Row.Cells[2].Style.Add("text-decoration", "blink");
 e.Row.Cells[2].Style.Add("color", "red");
Rajar AhmedConsultant
CERTIFIED EXPERT

Commented:
try this, have this script on your aspx page inorder to blink in IE.
//Cross browser function for blink process.
<script>
        function blink() {
            var blink = document.all.tags("BLINK");
            for (var i = 0; i < blink.length; i++)
                blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
        }

        function startBlink() {
            if (document.all)
                setInterval("blink()", 1000)
        }
        window.onload = startBlink;
    </script>

Open in new window

    protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[15].Text == "MCO" || e.Row.Cells[15].Text == "MMCO" )
            {
                e.Row.Cells[2].Text = "<blink>" + e.Row.Cells[0].Text.ToString() + "</blink>";
                e.Row.Cells[2].ForeColor = Color.Red;
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }
        }

        
    }

Open in new window


Meeran03

Author

Commented:
I have the timer script inserted into the Head and added the code behind; however,  as the column associated with the blinking feature is actually 1 with the header MCO ORDER.
With the code modified as requested it still not blinking.
Home1All.aspx
Home1All.aspx.cs
Rajar AhmedConsultant
CERTIFIED EXPERT

Commented:
Try this,
if (e.Row.RowType == DataControlRowType.DataRow){
            if (e.Row.Cells[15].Text == "AOG" || e.Row.Cells[15].Equals(DBNull.Value))
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }

            else if (e.Row.Cells[15].Text == "ETOPS - Working")
            {
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }

            else if (e.Row.Cells[15].Text == "AOG - R/T")
            {
                e.Row.BackColor = System.Drawing.Color.Tomato;
            }

            else if (e.Row.Cells[15].Text == "High Priority")
            {

                e.Row.BackColor = System.Drawing.Color.LightSkyBlue;

            }
            else if (e.Row.Cells[15].Text == "SOS - Working")
            {

                e.Row.BackColor = System.Drawing.Color.Orange;

            }
            else if (e.Row.Cells[15].Text == "Working Spare")
            {

                e.Row.BackColor = System.Drawing.Color.Aquamarine;

            }
            else if (e.Row.Cells[15].Text == "AOG - Vendor")
            {

                e.Row.BackColor = System.Drawing.Color.Orange;

            }
            else if (e.Row.Cells[15].Text == "AOG-Sched/Work Required")
            {

                e.Row.BackColor = System.Drawing.Color.Crimson;
            }
            else if (e.Row.Cells[15].Text == "AOG-Sched/Work Elective")
            {

                e.Row.BackColor = System.Drawing.Color.Coral;
            }
            else if (e.Row.Cells[15].Text == "Alert ETOPS Fly Day")
            {

                e.Row.BackColor = System.Drawing.Color.Fuchsia;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare - A/C Hooked - WU-cw")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare - Needs WU ck")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare - A/C Hooked - Needs WU")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Status Ready Spare - Needs WU-ck")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
        if (e.Row.Cells[15].Text == "High Priority")
        {

            e.Row.Cells[15].ForeColor = Color.Red;

        }
        if (e.Row.Cells[15].Text == "Alert Requires Verification Flight")
        {

            e.Row.Cells[15].ForeColor = Color.White;
            e.Row.BackColor = System.Drawing.Color.DarkRed;
        }
        if (e.Row.Cells[15].Text == "Alert Domestic Ops Only - Non Etops")
        {

            e.Row.Cells[15].ForeColor = Color.Red;
            e.Row.BackColor = System.Drawing.Color.Gold;
        }
        if (e.Row.Cells[15].Text == "AOG Off Station Repairs")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Yellow;
        }
        if (e.Row.Cells[15].Text == "AOG - SSE ATA Category Item")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Pink;
        }
        if (e.Row.Cells[15].Text == "MMCO-Open")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Yellow;
        }
        if (e.Row.Cells[15].Text == "MCO-Open")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Yellow;
        }
        if (e.Row.Cells[15].Text == "Alert ETOPS Qualified")
        {

            e.Row.Cells[15].ForeColor = Color.Red;
            e.Row.BackColor = System.Drawing.Color.Gold;
        }


        
            if (e.Row.Cells[15].Text == "MCO" || e.Row.Cells[15].Text == "MMCO")
            {
                HyperLink lnkMCO = (HyperLink)e.Row.Cells[1].Controls[0];
                lnkMCO.Text = "<blink>" + lnkMCO.Text.ToString() + "</blink>";
                lnkMCO.ForeColor = Color.Red;
                lnkMCO.Style.Add("text-decoration", "none");
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }
    }

Open in new window

Author

Commented:
Changed accordingly still not working.


public partial class _Home1All : System.Web.UI.Page
{

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
            if (e.Row.Cells[15].Text == "AOG" || e.Row.Cells[15].Equals(DBNull.Value))
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }

            else if (e.Row.Cells[15].Text == "ETOPS - Working")
            {
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }

            else if (e.Row.Cells[15].Text == "AOG - R/T")
            {
                e.Row.BackColor = System.Drawing.Color.Tomato;
            }

            else if (e.Row.Cells[15].Text == "High Priority")
            {

                e.Row.BackColor = System.Drawing.Color.LightSkyBlue;

            }
            else if (e.Row.Cells[15].Text == "SOS - Working")
            {

                e.Row.BackColor = System.Drawing.Color.Orange;

            }
            else if (e.Row.Cells[15].Text == "Working Spare")
            {

                e.Row.BackColor = System.Drawing.Color.Aquamarine;

            }
            else if (e.Row.Cells[15].Text == "AOG - Vendor")
            {

                e.Row.BackColor = System.Drawing.Color.Orange;

            }
            else if (e.Row.Cells[15].Text == "AOG-Sched/Work Required")
            {

                e.Row.BackColor = System.Drawing.Color.Crimson;
            }
            else if (e.Row.Cells[15].Text == "AOG-Sched/Work Elective")
            {

                e.Row.BackColor = System.Drawing.Color.Coral;
            }
            else if (e.Row.Cells[15].Text == "Alert ETOPS Fly Day")
            {

                e.Row.BackColor = System.Drawing.Color.Fuchsia;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare - A/C Hooked - WU-cw")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare - Needs WU ck")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Ready Spare - A/C Hooked - Needs WU")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
            else if (e.Row.Cells[15].Text == "Status Ready Spare - Needs WU-ck")
            {

                e.Row.BackColor = System.Drawing.Color.Lime;
            }
        if (e.Row.Cells[15].Text == "High Priority")
        {

            e.Row.Cells[15].ForeColor = Color.Red;

        }
        if (e.Row.Cells[15].Text == "Alert Requires Verification Flight")
        {

            e.Row.Cells[15].ForeColor = Color.White;
            e.Row.BackColor = System.Drawing.Color.DarkRed;
        }
        if (e.Row.Cells[15].Text == "Alert Domestic Ops Only - Non Etops")
        {

            e.Row.Cells[15].ForeColor = Color.Red;
            e.Row.BackColor = System.Drawing.Color.Gold;
        }
        if (e.Row.Cells[15].Text == "AOG Off Station Repairs")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Yellow;
        }
        if (e.Row.Cells[15].Text == "AOG - SSE ATA Category Item")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Pink;
        }
        if (e.Row.Cells[15].Text == "MMCO-Open")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Yellow;
        }
        if (e.Row.Cells[15].Text == "MCO-Open")
        {

            e.Row.Cells[15].ForeColor = Color.Black;
            e.Row.BackColor = System.Drawing.Color.Yellow;
        }
        if (e.Row.Cells[15].Text == "Alert ETOPS Qualified")
        {

            e.Row.Cells[15].ForeColor = Color.Red;
            e.Row.BackColor = System.Drawing.Color.Gold;
        }
   
            if (e.Row.Cells[15].Text == "MCO" || e.Row.Cells[15].Text == "MMCO")
            {
                HyperLink lnkMCO = (HyperLink)e.Row.Cells[1].Controls[0];
                lnkMCO.Text = "<blink>" + lnkMCO.Text.ToString() + "</blink>";
                lnkMCO.ForeColor = Color.Red;
                lnkMCO.Style.Add("text-decoration", "none");
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;

        Response.AddHeader("content-disposition",
                "attachment;filename=GridViewExport.doc");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-word ";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.RenderControl(hw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {

    }

}
Rajar AhmedConsultant
CERTIFIED EXPERT

Commented:
check whether your recieving MCO OR MMCO with upper case on cell15 do a debug and test whether its processing inside d loop of d above condition .

Author

Commented:
Ok I got it working.   It is not applying fore color of "Red" however.   Would it be difficult to make the entire background color Blink or alternate colors??   Trying to bring as much attention to this information as possible.
Consultant
CERTIFIED EXPERT
Commented:
change these Codes .
Step1:Codebehind
 if (e.Row.Cells[15].Text == "MCO" || e.Row.Cells[15].Text == "MMCO")
            {
                HyperLink lnkMCO = (HyperLink)e.Row.Cells[1].Controls[0];
                lnkMCO.Text = "<FONT class='jqueryBlink'>" + lnkMCO.Text.ToString() + "</FONT>";
                //lnkMCO.ForeColor = Color.Red;
                lnkMCO.Style.Add("text-decoration", "none");
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }

Open in new window

Step 2 : On Aspx : Remove or Comment old script . Add Jquery Lib and add new script given below
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
/* Remove this or remove this function - Starts
  function blink() {
        var blink = document.all.tags("BLINK");
        for (var i = 0; i < blink.length; i++)
            blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
    }

    function startBlink() {
        if (document.all)
            setInterval("blink()", 1000)
    }
    window.onload = startBlink;
Comment this or remove this function 
*/

function blink() {
        var blink = document.all.tags("FONT");
        for (var i = 0; i < blink.length; i++) {
            if (blink[i].className = 'jqueryBlink') {
                blink[i].parentNode.parentNode.className = blink[i].parentNode.parentNode.className == "blinkCss" ? "altblinkCss" : "blinkCss";
            }
        }
    }
    $(document).ready(function () {
        setInterval(blink, 1000);
    });

</script>

Open in new window

Step 3: on Aspx add this css class
<style type="text/css">
.blinkCss
{
  background-color:Orange;   
}
.blinkCss font
{
  color:Black;     
    }
.altblinkCss
{
  background-color:red;
  
}
.altblinkCss font
{
  color:white;      
}

</style>

Open in new window


Hope this helps u.

Author

Commented:
Works great.   Thx so much for your assistance.    It's been a please

Author

Commented:
Excellant response time with accurate information easy to understand.   Thx so much.
Rajar AhmedConsultant
CERTIFIED EXPERT

Commented:
Thank u for the grade and appreciation .
Meeran03