基于某些条件的Gridview行闪烁
本文关键字:闪烁 Gridview 于某些 条件 | 更新日期: 2023-09-27 18:10:30
我有这个gridview,其中我希望某些行基于某些条件眨眼。我试过javascript和jquery,但都不起作用。
javasccript例子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行闪烁所需的条件,您可以在代码本身中看到,当status被raise并且AckDate和ClearDate为null或空时,它应该闪烁。状态,AckDate,ClearDate以列的形式出现在网格中,你可以在代码中看到。
上面的代码有什么问题?还有其他方法可以解决这个问题吗?
尝试使用此链接
`<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>`
或者你可以从他们的网站下载最新的jquery并将其包含在你的项目中