基于该行中的列的值行的变化颜色 [英] Change color of row based on value of a column in the row

查看:84
本文介绍了基于该行中的列的值行的变化颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有负载,从我的服务器上的数据,并将其在DataGrid将SqlDataSource。

我有一个名为列clnumber有,数字1,2,3

我要的是每一行都有不同的颜色取决于哪个号码是在数据行列

这是code我用

  $(文件)。就绪(函数(){    $(#<%= GridView1.UniqueID%GT; TR)。每个(函数(){        。变种数= $(本)。儿童(TD:EQ(6))文本();        如果(数字=='OK'){
            $(本)。儿童('TD')的CSS({背景颜色:浅绿});        }
    })
});


解决方案

就算你给你的GridView称为myGridViewCSS类,你可以做到以下几点:

  $(文件)。就绪(函数(){    $('。myGridView TR')。每个(函数(){        。变种数= $(本)。儿童(TD:EQ(1))文本();        如果(数=='1'){
            $(本)。儿童('TD')的CSS(背景,红)。
        }
    })
});

其中TD:EQ(1)是指连续第二个单元格。当然,这将取决于你的单元格行中包含此神奇的数字。

我敢肯定这不是最优雅的使用jQuery的,但你愿意,你可以重构它

I have an sqldatasource that loads, data from my server and puts it in a datagrid.

I have a Column named clnumber that has, the numbers 1,2,3

What I want is that each row have a different color depending on which number is in that datarow column

THIS IS THE CODE I USED

 $(document).ready(function () {

    $("#<%=GridView1.UniqueID%> tr").each(function () {

        var number = $(this).children('td:eq(6)').text();

        if (number == 'OK') {
            $(this).children('td').css({ "background-color": "lightgreen" });

        }
    })
});

解决方案

Granted you've given your gridview a css class called 'myGridView' you could do the following:

$(document).ready(function () {

    $('.myGridView tr').each(function () {

        var number = $(this).children('td:eq(1)').text();

        if (number == '1') {
            $(this).children('td').css('background', 'red');
        }
    })
});

where 'td:eq(1)' refers to the second cell in a row. This of course will depend on what cell in your row contains this magic number.

I'm certain it's not the most elegant use of jQuery, but you could refactor it as you wish

这篇关于基于该行中的列的值行的变化颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆