现在的位置: 首页 > 综合 > 正文

根据条件动态改变GridView某行或某个单元格的背景色

2013年05月03日 ⁄ 综合 ⁄ 共 851字 ⁄ 字号 评论关闭
突出显示成绩cj表(id,english,computer)中学生不及格的分数
1。突出显示不及格分数所在行
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataRowView drv;
        if(e.Row.RowType==DataControlRowType.DataRow)
        {
            drv = e.Row.DataItem as DataRowView;
            if (Convert.ToInt32(drv["computer"].ToString()) < 60 || Convert.ToInt32(drv["english"].ToString()) < 60)
                e.Row.BackColor = System.Drawing.Color.Red;
        }
    }
2。突出显示不及格分数所在单元格
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Convert.ToInt32(e.Row.Cells[1].Text) < 60)
                e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
            if (Convert.ToInt32(e.Row.Cells[2].Text) < 60)
                e.Row.Cells[2].BackColor = System.Drawing.Color.Red;
        }               
    }

抱歉!评论已关闭.