DataGrid 的某行怎么变为红色 在数据库中一个字段的值: 1是显示红色,0是正常在界面上,如果是1,DataGrid中的一行变为红色,0为不变色 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在datagrid1的ItemDataBound事件中:if 要判斷的字段的值=1 then e.Item.BackColor = System.Drawing.Color.Redend if e.Item.Style.Add("bgcolor", "Red")这样也行 同意1楼,不过补充一下,在itemDataBound事件中,加入if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer){if 要判斷的字段的值==1 then e.Item.BackColor = System.Drawing.Color.Redend if} 可以通过datagrd在绑定数据的ItemDataBound事件时候将这段脚本加入进去。具体代码如下:if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){e.Item.Cells[2].Attributes.Add("onmouseover","this.style.backgroundColor='Red'");e.Item.Cells[2].Attributes.Add("onmouseout","this.style.backgroundColor='原来的颜色'");} public void Item_Bound(object sender,DataGridItemEventArgs e) { if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { int j; if(e.Item.ItemIndex == -1) return; i = i + 1; j = i % 2; if(j == 1) { e.Item.BackColor = Color.FromArgb(240,255,240); e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#f0fff0'"); } else { e.Item.BackColor = Color.FromArgb(255,255,204); e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffcc'"); } e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='#ffeeff'"); e.Item.Style.Add("cursor","hand"); e.Item.Attributes.Add("onclick","location.href='contents_up.aspx?contents_id=" + e.Item.Cells[0].Text + "&Code="+Code+"'"); } } if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer) { if(e.Item.Cells[4].Text==true.ToString()) e.Item.BackColor = System.Drawing.Color.Red; } 如何发送邮件不被拦截? 怎样查询视图速度最快 预览文件的问题。急! 我现在有个软件产品,怎样能给这个产品加上序列号 Regex是什么类 在aspnet2.0中,如果在webpart中加载ascx文件? 打包问题急急! 为什么aspx文件放虚拟主机的子文件夹下出错,火速超急,谢谢,虚拟主机提供商www.dns.com.cn标准型的 高手指点一下ViewState报错了 求在开发ASP.net项目的数据库设计方案 怎么样处理OnPageIndexChanging才能实现数据分页 关于Request.QueryString的一点问题!
e.Item.BackColor = System.Drawing.Color.Red
end if
{
if 要判斷的字段的值==1 then
e.Item.BackColor = System.Drawing.Color.Red
end if}
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
e.Item.Cells[2].Attributes.Add
("onmouseover","this.style.backgroundColor='Red'");
e.Item.Cells[2].Attributes.Add
("onmouseout","this.style.backgroundColor='原来的颜色'");
}
{
if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
int j;
if(e.Item.ItemIndex == -1)
return;
i = i + 1;
j = i % 2;
if(j == 1)
{
e.Item.BackColor = Color.FromArgb(240,255,240);
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#f0fff0'");
}
else
{
e.Item.BackColor = Color.FromArgb(255,255,204);
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffcc'");
} e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='#ffeeff'");
e.Item.Style.Add("cursor","hand");
e.Item.Attributes.Add("onclick","location.href='contents_up.aspx?contents_id=" + e.Item.Cells[0].Text + "&Code="+Code+"'");
}
}
{
if(e.Item.Cells[4].Text==true.ToString())
e.Item.BackColor = System.Drawing.Color.Red;
}