c# - Issue with changing Gridview cell color depending on condition -
i trying change cell color of gridview, if dot < today's date. issue changes red rows dot column though dot column > today's date.
here code
protected void onrowdatabound_gvtest(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.datarow) { label lbldot = (label)e.row.findcontrol("dot"); datetime dotdate = datetime.parse(lbldot.text); if (dotdate < datetime.now) { //e.row.backcolor = system.drawing.color.red; gvdriverstatus.columns[3].itemstyle.forecolor = system.drawing.color.red; } } }
this:
gvdriverstatus.columns[3].itemstyle.forecolor = ...
will change color of whole column. change cell color, use:
e.row.cells[3].forecolor = ...
Comments
Post a Comment