[英]Change colors of table row if column contains certain value
I have a table that looks something like this: 我有一张桌子,看起来像这样:
<asp:Repeater ID="myRepeater" runat="server">
<div id="divTable" class="divTable">
<table id="myTable">
<thead>
<tr>
<td>A</td>
</tr>
<tr>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
<tr>
<td>D</td>
</tr>
</thead>
<tbody id="myContent">
<tr>
<td>Some Text</td>
</tr>
<tr>
<td>Some Text</td>
</tr>
<tr>
<td>Some Text</td>
</tr>
<tr>
<td id="findMe">
<%#Eval("IsFlagged")%>
</td>
</tr>
</tbody>
</asp:Repeater>
</table>
</div>
Now, here's what I'm trying to do. 现在,这就是我想要做的。 If <%#Eval("IsFlagged")%> returns anything at all , i'd like to make all the cells in the table row a certain color. 如果<%#Eval(“ IsFlagged”)%>根本不返回任何内容 ,我想使表行中的所有单元格都具有某种颜色。
I've been reading about .contains(), but I haven't found an example that simply asks "if not null, apply a .css style to the rest of the cells of the table row". 我一直在阅读有关.contains()的信息,但我还没有找到一个简单的示例来询问“如果不为null,则将.css样式应用于表行的其余单元格”。
I put together an example in jsfiddle: http://jsfiddle.net/aMR5r/ 我在jsfiddle中放了一个示例: http : //jsfiddle.net/aMR5r/
Edit: Your edit makes the code a little simpler, but it's the same principle. 编辑:您的编辑使代码更加简单,但这是相同的原理。
$(function(){
var isFlagged = $('#findMe').text();
if(isFlagged.length > 0)
{
$('#findMe').parent().addClass('yellow');
}
});
First, try to give that specific td a class or someting so you can target it. 首先,尝试给特定的td一个类或某物,以便您可以定位它。 Then you can check the length of $('td.yourclassname').html(); 然后,您可以检查$('td.yourclassname')。html();的长度。
If you are using VB.Net then you can use this code.. 如果您使用的是VB.Net,则可以使用此代码。
<tr style="background-color:<%# IIF(IsDBNull(Eval("IsFlagged"),"none","yellow") %>">
you can apply this logic to TD also. 您也可以将此逻辑应用于TD。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.