根据条件改变GridView单元格背景颜色或者添加背景图片
现在的GridView的各个单元格里都有数据,相应的Footer里也有所有的汇总数据,现在想根据每个单元格的数据,占汇总数据的百分比,设置此单元格的背景色或图片
比如说某单元格的数据是30,汇总数据是100,想达到的效果是这个单元格的背景色只填充30%,可不可以做到背景色只填充30%的宽度,或者用背景图片只拉伸这个单元格宽度的30%
请问怎么做到,在线求结果啊!
[解决办法]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[6].Text == "0")
{
e.Row.Cells[6].Text = "未处理";
}
else if (e.Row.Cells[6].Text == "1")
{
e.Row.Cells[6].Text = "已处理";
e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
}
if (e.Row.Cells[7].Text == "False")
{
e.Row.Cells[7].Text = "未复核";
((Button)e.Row.Cells[7].FindControl("btn_check")).CommandName = "check";
((Button)e.Row.Cells[7].FindControl("btn_check")).Text = "复核";
}
else if (e.Row.Cells[7].Text == "True")
{
e.Row.Cells[7].Text = "已复核";
((Button)e.Row.Cells[7].FindControl("btn_check")).CommandName = "uncheck";
((Button)e.Row.Cells[7].FindControl("btn_check")).Text = "反复核";
e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
}
}

$(function () {
var col = $('#GridView1 td:nth-child(1):not(:last)'); // 选择单元格,比如第一列但除了最后一格总计, 单元格中必须是数字
var total = $('#GridView1 td:nth-child(1):last').text(); // 总计数,比如第一列最后一格
col.each(function () {
$(this).css({ width:'100px', textAlign:'center', position:'relative'})
.append('<div style="background:red; position:absolute; top:0; height:100%; width:'
+ $(this).text() / total * 100 + '%;"/>');
});
});