gridview行根据某些条件闪烁

时间:2014-06-26 18:51:34

标签: c# javascript jquery asp.net gridview

我有这个gridview,我希望某些行根据某些条件闪烁。 我尝试过javascript和jquery,但没有任何效果。

javasccript example

jquery

我在上面的链接中尝试了jquery,但它给了我错误

  

0x800a1391 - JavaScript运行时错误:' $'未定义

我实际上想要使用它因为它符合我当前的要求。 我目前的要求是,满足3组条件的行应该闪烁

<style type="text/css">
    .bgRow
    {
        background-color: white;
    }
    .norRow
    {
        background-color: Silver;
    }
</style>
<script src="~/Scripts/jquery-1.8.2.js"></script>
    <script src="yourUrl/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function setBG(GridAlarm)
        {
        var id = "#" + GridAlarm;
        $(id).find("tr").each(function ()//error comes here while debuggigng
        {
            var css = $(this).attr("class");
            if (css != null && css == "bgRow")
                $(this).addClass("norRow").removeClass("bgRow");
            else if (css != null && css == "norRow")
                $(this).addClass("bgRow").removeClass("norRow");

        });
        setTimeout("setBG('" + GridAlarm + "')", 1000); //1000 is equal to one second and call function every one second.
    }
</script>

设计中的gridview代码

<asp:GridView ID="GridAlarm" CssClass="bgRow" EmptyDataText="NoData" CellPadding="7" CellSpacing="1" runat="server" DataKeyNames="id" AutoGenerateColumns="false" ShowHeader="true" OnRowDataBound="GridAlarm_RowDataBound" OnPageIndexChanging="GridAlarm_PageIndexChanging">
    <Columns>
        <asp:BoundField DataField="TagName" HeaderText="TagName" />
        <asp:BoundField DataField="Description" HeaderText="Description" />
        <asp:BoundField DataField="Value" HeaderText="Value"  />
        <asp:BoundField DataField="AlarmStatus" HeaderText="Alarm Status"/>
        <asp:BoundField DataField="AlarmRaisedDateTime" HeaderText="Alarm Raised"  />
        <asp:BoundField DataField="AlarmClearedDateTime" HeaderText="Alarm Cleared"  />
        <asp:BoundField DataField="AlarmAckDateTime" HeaderText="Alarm Acknowledgement"  />
        <asp:TemplateField HeaderText="Select">
          <ItemTemplate>
              <asp:CheckBox ID="chk_delete" runat="server" />
          </ItemTemplate>
         </asp:TemplateField>
    </Columns>
</asp:GridView>

及以下代码

protected void GridAlarm_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        alarmStat = (e.Row.Cells[3].Text);
        ClearDate = (e.Row.Cells[5].Text);
        AckDate = (e.Row.Cells[6].Text);

        foreach (TableCell cell in e.Row.Cells)
        {
            if (alarmStat.Equals(System.Configuration.ConfigurationManager.AppSettings["A_Clear"].ToString()))
            {
                cell.BackColor = System.Drawing.Color.Green;
                cell.ForeColor = System.Drawing.Color.White;
            }
            else if (alarmStat.Equals(System.Configuration.ConfigurationManager.AppSettings["A_Raise"].ToString()))
            {
                if (!string.IsNullOrEmpty(AckDate) && (string.IsNullOrEmpty(ClearDate)))
                {
                    cell.BackColor = System.Drawing.Color.Red;
        cell.ForeColor = System.Drawing.Color.White;
                }
                else if (string.IsNullOrEmpty(AckDate) && (string.IsNullOrEmpty(ClearDate)))
                {
                    e.Row.CssClass = "bgRow";
                }
            }
        }
    }
}

我还必须在页面加载中添加以下内容

ClientScript.RegisterStartupScript(GetType(), "BG", "setBG('" + GridAlarm.ClientID + "')", true);

但它如上所述给出错误..

至于gridview行闪烁所需的条件,你可以在代码本身看到,当状态为Raised并且AckDate和ClearDate为null或为空时它应该闪烁。 状态,AckDate,ClearDate在网格中显示为列,您可以在代码中看到。

上面的代码有什么问题? 还有其他方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

尝试使用此链接

`<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>` 

或者您可以从他们的网站下载最新的jquery并将其包含在您的项目中。