Change Gridview row color based on some condition in javascript or jquery?

Posted by Rajesh_Kumar under JavaScript on 7/3/2015 | Points: 10 | Views : 1098 | Status : [Member] [MVP] | Replies : 2
Hi All,
How to change Gridview row color based on some condition in javascript or jquery?
Suppose i have one column named is_active which stores Y/N. I want to change row color to something if is_active flag is 'Y'.
How do i do that?
I also searched on google but did not get satisfactory answer.

Rejesh Kumar


Responses

Posted by: Sheonarayan on: 7/3/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Rajesh,

Thanks for asking. You may not get exact solution of your problem using Google. You will have to get hints from several question and solve your problem.

I have written this article explicitly for you solving your problelm http://www.dotnetfunda.com/articles/show/3123/changing-grid-row-style-based-on-condition-in-jquery. You just need to change "False" to "N" in your condition in the jQuery code and change the css style you want.

Hope this will help.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Rajesh_Kumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sojanya on: 7/6/2015 [Member] Starter | Points: 25

Up
0
Down
Hi Rajesh,

I hope you must have gone through the link Sheonarayan provided above.
Here is the approach in explanation to achieve, highlighting row in table on any condition.

I will personally suggest you to add either a hidden field or any additional custom attribute to some control in each row of your table. Which you should be able to pick in jQuery. Choice is yours, just bind the data on which you have to add some condition.

Then iterate through the entire table using jQuery each() method. Sample code is below:

$('#tableId tr').each(function (index) {
var row = $(this);
if (CONDITION) {
row.css("background-color", "Gray");
}
});

Here giving ID of table in jQuery selector is always better because it is faster than class selector.

Regards,
Sojanya Tripathi
www.dotnetguidance.com

Rajesh_Kumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response