我正在尝试根据 gridview 中每一行中的布尔值(布尔值)修改进度条的颜色。如果值为 True,则颜色将为绿色,如果值为 False,则颜色将为红色。但由于某种原因,设置颜色的条件不起作用!
提前致谢:
Asp GridView 代码:
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="progress" HeaderText="Progress" SortExpression="progress" />
<asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />
<asp:TemplateField>
<ItemTemplate>
<div class="pbcontainer">
<div class="progressbar"><span><%# Eval("progress") %>%</span></div>
<div class="value" style="visibility:hidden; height:0; width:0;"> <%# Eval("progress") %> </div>
<div class="status" style="visibility:hidden; height:0; width:0;"> <%# Eval("status") %> </div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
脚本:
</style>
<link href="CSS/jquery-ui.css" rel="stylesheet" />
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/jquery-ui-1.10.3%20.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function () {
$('.pbcontainer').each(function () {
var val = parseInt($(".value", this).text());
var status = $(".status", this).text();
var progressColor = "Orange";
var progressBackColor = "lightYellow";
console.log(status);
if (status == "False") {
progressColor = "Red";
//console.log("Condition met color red status Flase");
}
else if (status == "True") {
progressColor = "Green";
//console.log(progressColor);
//console.log("Condition not met color Green status True");
}
$('.progressbar', this).progressbar({ value: val });
$('.progressbar', this).css({ 'background': progressBackColor });
$('.progressbar > div', this).css({ 'background': progressColor });
});
});
</script>