gridview的排闪烁根据一定的条件 [英] gridview row blinking based on some conditions

查看:325
本文介绍了gridview的排闪烁根据一定的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的GridView这,我想基于一些条件的某些行闪烁。
我曾尝试的JavaScript和jQuery,但毫无效果。

I have this gridview which in which I want certain rows to blink based on some conditions. I have tried javascript and jquery but nothing worked.

javasccript例如

jQuery的

我试着在上面的链接jQuery的,但它给我的错误

I tried jquery in above link but it is giving me error

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

0x800a1391 - JavaScript runtime error: '$' is undefined

其实我是想怎么把它在我的电流需求相匹配使用它。
我现在的需求有,满足3组条件的行会闪烁

I actually want to use it coz it matches my current requirement. My current requirement has that, rows which satisfies 3 set of conditions should blink

<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 code设计

the gridview code in design

<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>

和低于code后面

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";
                }
            }
        }
    }
}

我也不得不加入页面加载以下

i also had to add following in page load

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

但它给错误如上所述..

But it gives error as mentioned above..

至于闪烁,你可以在code本身就是当状态上升和AckDate和ClearDate为null或空就应眨眼看到需要为GridView行的条件..
状态,AckDate,ClearDate是present在网格列,你可以在code看到的。

As for the conditions required for the gridview rows to blink you can see in code itself that is it should blink when status is Raised and AckDate and ClearDate are null or empty.. Status,AckDate,ClearDate are present as columns in grid as you can see in code.

这有什么不对上述code?
有没有我可以解决这个问题的任何其他方式?

What is wrong in above code? Is there any other way I can solve this problem?

推荐答案

尝试使用此链接

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

或者你可以从他们的网站上下载最新的jQuery和包含在您的项目。

or you can download latest jquery from their site and include it in your project.

这篇关于gridview的排闪烁根据一定的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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