请问,先将从数据库里查询的结果保存到dataset中,然后绑定到datagrid,现在想把查询结果中满足某些条件的记录的一个字段突出显示(红色),该怎么办呢?
比如:我现在要查找学生的成绩:
select StudentName,CourseName,score
from t_StudentCourse
where user_id=1001
恰好1001号学生的成绩中有一门不及格,需要把不及格的那个分数(比如59)突出显示出来,要怎么办呢?
比如:我现在要查找学生的成绩:
select StudentName,CourseName,score
from t_StudentCourse
where user_id=1001
恰好1001号学生的成绩中有一门不及格,需要把不及格的那个分数(比如59)突出显示出来,要怎么办呢?
找到成绩对应的列,取出值,做比较
小于60就变个颜色,不小于就不管不就行了。
private void DataGrid2_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.Cells[1].Text =="100")
e.Item.Cells[1].ForeColor = System.Drawing.Color.Red;
}
Int(DataBinder.Eval(Container.DataItem, "score ").ToString())<60)%>
CleanString.color(string str,bool bo) //这个控制颜色,大小方法
我感觉这样会更好!
{
for(int i=0;i<GridView1.Rows.Count;i++)
{
if (Convert.ToInt32(GridView1.Rows[i].Cells[2].Text) < 60)
{
GridView1.Rows[i].Cells[2].Text = "<font color='red'>" + GridView1.Rows[i].Cells[2].Text + "</font>";
}
}
}
protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView data = (DataRowView)e.Row.DataItem; if (Convert.ToDecimal(data["score"].ToString()) < 60)
{
e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
} }
}
4楼的办法用在datagrid上也可以吧,是不是只要把GridView1修改成datagrid1就可以了呢?我现在这个机子上没有装2003,没有办法调试。你个的方法在2005里面是可以的。