473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Conditional statement using clock & datagrid

5
Hi all,

I fairly new to asp.net, and I need some help with writing a conditional statement to change a background row color of a data-table based on a JavaScript clock I have running on the webpage.

There is a particular column on my Datagrid called scheduled time, where I want that column to listen to the clock that I have defined on the webpage. The Datagrid table rows should change background colors based on the "scheduledTime" compared to the clock. There is a xlsx attached for a visual reference.


Expand|Select|Wrap|Line Numbers
  1. // Clock variables
  2.  
  3.   var currentTime = new Date ( );
  4.  
  5.   var currentHours = currentTime.getHours ( );
  6.   var currentMinutes = currentTime.getMinutes ( );
  7.   var currentSeconds = currentTime.getSeconds ( );

Thank you all for taking the time!
Attached Files
File Type: xlsx example.xlsx (9.2 KB, 371 views)
Dec 20 '12 #1
1 2131
Frinavale
9,735 Expert Mod 8TB
A DataGrid is rendered as an HTML <table> and it is given an ID which is automatically generated by ASP.NET to ensure that all HTML elements in the page have a unique ID (ensuring that the HTML is valid).

You can retrieve the HTML ID that is generated for the ASP.NET control using the ClientID property.

Check out this insight about How to use JavaScript in ASP.NET to get started. If you don't want to generate your JavaScript in your C# or VB.NET code behind, you could also use ASP shorthand to write the ClientID directly into the page like this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.   function changeColumnColor(){
  3.     var dataGridTable = document.getElementById("<%=myDataGrid.ClientID%>");
  4.     //.....
  5.   }
  6. </script>
You can use the JavaScript getElementByID(id) method to retrieve the table in your JavaScript function that will set the column's color after a given time (using the settimeout(function) method).

Once you have a reference to the table, you can use the getElementsByTagName() method to retrieve all of the table rows (<tr>s).

Loop through all of the <tr>s and within that loop use the getElementByTagName method to retrieve all of the <td>s for the row... loop through these to retrieve the column you are looking for and set the style for the element to the desired style.

-Frinny
Dec 29 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I...
8
by: arganx | last post by:
The conditional statement "if(j.... always executes regardless of what you enter. BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buffer=""; GetWindowText(hwnd,buffer,256);...
5
by: Gary Wessle | last post by:
Hi if I have a method like this bool myClass::myMothod(myType& mt, herType ht) throw ( SomeExp ); how can I use it in a conditional statement if ( try {
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
5
by: bamn68 | last post by:
how do i use conditional statement in sql? im using access 2003 as frontend and backend. What would be the SQL statement for the situation below? I would like to count the number of records in...
1
by: barcaroller | last post by:
I was looking at some code that uses fstream: #include <fstream> // // which includes: // istream& getline( char* buffer, streamsize num ); // ifstream fin;
0
by: cljordan | last post by:
I am trying to create a database that list materials and their quantities, and highlights quantities that come up outside a certain percentage range against the average. I have tried the following...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.