改变gridview颜色

xqjstxz 2010-12-14 04:09:48
我在gridview中获取到了一系列客户数据,当初录入客户的时候时间是自动获取的,现在我想让存在三十天的客户的信息改变颜色,也就是在控件中能够与其他的客户区分开来,请问有没有比较好的方法啊?????
...全文
243 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanjiazhu 2011-06-23
  • 打赏
  • 举报
回复
加油!关键是做判断,当30日内,或当月内,then ……什么颜色,else什么颜色……
ycproc 2011-06-23
  • 打赏
  • 举报
回复
不要回帖了
这是什么时候的帖子啊

一禅(OneZen) 2011-06-23
  • 打赏
  • 举报
回复
vs 选一个gridview,按住F4,设置它的属性,就OK

如果你的页面加了主题,那你就在Css样式里面写,再调用它的样式。
juxianxiang 2011-06-23
  • 打赏
  • 举报
回复
后台判断,如果为真则

<p color=red>value</p>
Momo 2011-06-23
  • 打赏
  • 举报
回复
终于解决了,我心激动啊,多谢各位大神,O(∩_∩)O哈哈哈~
  • 打赏
  • 举报
回复

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[1].Text.Trim() .....) //判断时间
{
e.Row.Cells[1].ForeColor = System.Drawing.Color.Red; //将需要的内容能够的显示为红色
}
}

Issac25Name 2010-12-14
  • 打赏
  • 举报
回复
建议楼主还是手动写信息列表比较方便,想怎么设置就怎么设置,给楼主一个样板:

<div runat="server" align="center" style=" width:100%">
<%
if (checkList.Count == 0)
{
Response.Write("<table align=\"center\" runat=\"server\" style=\"width:100%\" ><tr style=\"background-color:#A2D268\">");
Response.Write("<td>用药信息</td><td>患者信息</td><td>不良反应</td><td>国内情况</td><td>检报人信息</td><td>备注</td></tr>");
Response.Write("<tr><td colspan=\"6\">目前还没有不良反应举报信息!</td></tr></table>");
}
else
{
Response.Write("<table align=\"center\" runat=\"server\" style=\"width:100%;border-color:Blue;\" rules=\"rows\" border=\"2px\"><tr style=\"background-color:#A2D268\">");
Response.Write("<td>编号</td><td>患者信息</td><td>用药信息</td><td>不良反应</td><td>国内情况</td><td>检报人信息</td><td>备注</td></tr>");
for (int i = 0; i < checkList.Count; i++)
{
Model.Check model = checkList[i];

Response.Write("<tr style=\"cursor:hand\" onmouseover=\"this.bgColor='yellow'\" onmouseout=\"this.bgColor='#ffffff'\" onclick=\"OpenMessage('" + model.Id + "')\">");
Response.Write("<td valign=\"middle\" align=\"center\">" + (i + 1) + "</td>");
Response.Write("<td valign=\"top\" style=\"font-size: small; color: #7B7B7B\">");
if (model.Patient.Length > 10)
Response.Write(model.Patient.Substring(0, 10) + "...");
else
{
Response.Write(model.Patient);
}
Response.Write("</td>");
Response.Write("<td valign=\"top\" style=\"font-size: small; color: #7B7B7B\">");
if (model.AboutDrug.Length > 10)
Response.Write(model.AboutDrug.Substring(0, 10) + "...");
else
{
Response.Write(model.AboutDrug);
}
Response.Write("</td>");

Response.Write("<td valign=\"top\" style=\"font-size: small; color: #7B7B7B\">");
if (model.Reaction.Length > 10)
Response.Write(model.Reaction.Substring(0, 10) + "...");
else
{
Response.Write(model.Reaction);
}
Response.Write("</td>");
Response.Write("<td valign=\"top\" style=\"font-size: small; color: #7B7B7B\">");
if (model.National.Length > 10)
Response.Write(model.National.Substring(0, 10) + "...");
else
{
Response.Write(model.National);
}
Response.Write("</td>");
Response.Write("<td valign=\"top\" style=\"font-size: small; color: #7B7B7B\">");
if (model.Reporter.Length > 10)
Response.Write(model.Reporter.Substring(0, 10) + "...");
else
{
Response.Write(model.Reporter);
}
Response.Write("</td>");
Response.Write("<td valign=\"top\" style=\"font-size: small; color: #7B7B7B\">");
if (model.Note.Length > 10)
Response.Write(model.Note.Substring(0, 10) + "...");
else
{
Response.Write(model.Note);
}
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
}

%>
</div>


我在我们所有项目里面都是用这种方式写的!表面上看着比较复杂,其实只要你把握好table、tr、td就完全搞定了!并且想要实现什么格式直接在里面就可以添加判断并设置!
希望对楼主有所帮助
fendouaj 2010-12-14
  • 打赏
  • 举报
回复
首先判断时间,然后设置该行的颜色就可以了。
ycproc 2010-12-14
  • 打赏
  • 举报
回复
wuyq11 2010-12-14
  • 打赏
  • 举报
回复
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//判断
e.Row.BackColor = System.Drawing.Color.Read;
}
}
或设置<%# GetColor((DateTime)Eval("a"),(GridViewRow)Container)%>
public void GetColor(DateTime dt,GridViewRow row)
{
row.BackColor = Color.Red;
}
yl19831983 2010-12-14
  • 打赏
  • 举报
回复
百度下 GridView72般变化 就知道呢
沙伽more 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 happying_e 的回复:]

C# code

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (判断时间)
{
e.Row.Cells[11].B……
[/Quote]

借花献佛,学习
johneyson 2010-12-14
  • 打赏
  • 举报
回复
楼上正解
米娅 2010-12-14
  • 打赏
  • 举报
回复

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (判断时间)
{
e.Row.Cells[11].BackColor = System.Drawing.Color.Red;
}
}
}

ruanjian2110 2010-12-14
  • 打赏
  • 举报
回复
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string str = e.Row.Cells[11].Text;
if (str == "断电")
{
e.Row.Cells[11].BackColor = System.Drawing.Color.Red;
}
//查找关键字
if (str.Contains("断电"))
{
string newStr = "<font color=red>" + str + "</font>";

e.Row.Cells[11].Text = str.Replace("断电", newStr);
}

}
}
你判断下日期就可以了.
离洛 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xqjstxz 的回复:]
那怎么设置呢?
[/Quote]
大家给的都是理论,貌似你想要源码?
你把思路理清之后,代码还不会写嘛?
xqjstxz 2010-12-14
  • 打赏
  • 举报
回复
那怎么设置呢?
wjy217213 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
在绑定事件里判断日期,然后设置
[/Quote]

up
xqjstxz 2010-12-14
  • 打赏
  • 举报
回复
有没有人帮忙啊?很着急的~~~~谢谢啦~~~
孟子E章 2010-12-14
  • 打赏
  • 举报
回复
在绑定事件里判断日期,然后设置

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧