0

我正在尝试根据 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>
4

2 回答 2

1

由于状态周围有额外的空格,条件不正确..

您需要修改代码以像这样修剪空白

 var status = $.trim( $(".status", this).text() );

检查此演示 http://jsfiddle.net/aXTcV/1/

于 2013-08-08T11:15:40.363 回答
0

尝试这个:

<script type="text/javascript">
    $(function () {
        $('.pbcontainer').each(function () {
            var this_Progress = $(this);
            var val = parseInt($.trim(this_Progress.find('.value').text()));
            var status = $.trim(this_Progress.find('.status').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");
            }
            this_Progress.find('.progressbar').progressbar({ value: val });
            this_Progress.find('.ui-progressbar').css({ 'background': progressBackColor });
            this_Progress.find('.ui-progressbar-value').css({ 'background': progressColor });

        });
    });
</script>
于 2013-08-08T11:18:01.043 回答