您的位置:首页 > 编程语言 > ASP

aspx GridView的RowDataBound中改变单元格大小,颜色,汇总等

2012-02-23 11:10 525 查看
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)

{

e.Row.Cells[0].Attributes.Add("style", "width:40px");

e.Row.Cells[1].Attributes.Add("style", "width:60px");

e.Row.Cells[2].Attributes.Add("style", "width:60px");

e.Row.Cells[3].Attributes.Add("style", "width:60px");

e.Row.Cells[4].Attributes.Add("style", "width:60px");

e.Row.Cells[5].Attributes.Add("style", "width:75px");

e.Row.Cells[6].Attributes.Add("style", "width:75px");

e.Row.Cells[7].Attributes.Add("style", "width:75px");

e.Row.Cells[8].Attributes.Add("style", "width:75px");

e.Row.Cells[9].Attributes.Add("style", "width:75px");

e.Row.Cells[10].Attributes.Add("style", "width:75px");

e.Row.Cells[11].Attributes.Add("style", "width:110px");

e.Row.Cells[12].Attributes.Add("style", "width:110px");

e.Row.Cells[13].Attributes.Add("style", "width:110px");

e.Row.Cells[14].Attributes.Add("style", "width:140px");

e.Row.Cells[15].Attributes.Add("style", "width:40px");

e.Row.Cells[16].Attributes.Add("style", "width:40px");

if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Cells[5].ForeColor = System.Drawing.Color.DarkRed;

e.Row.Cells[6].ForeColor = System.Drawing.Color.DarkBlue;

e.Row.Cells[7].ForeColor = System.Drawing.Color.DarkGreen;

e.Row.Cells[8].ForeColor = System.Drawing.Color.DarkRed;

e.Row.Cells[9].ForeColor = System.Drawing.Color.DarkBlue;

DataRowView dr = e.Row.DataItem as DataRowView;

if (dr.Row[bilv].ToString().Trim() == "")

{

}

else

{

numbil += Convert.ToDouble(dr.Row[bilv]);

if (Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0] == "0" || Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0] == "-0")

{

e.Row.Cells[13].Text = "0";

}

else

{

//Math.Round(Convert.ToDouble(Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0]), 2, MidpointRounding.AwayFromZero);

e.Row.Cells[13].Text = Math.Round(Convert.ToDouble(Convert.ToDouble(dr.Row[bilv]).ToString().Split('.')[0]), 0, MidpointRounding.AwayFromZero).ToString();

}

}

if (dr.Row[bidui].ToString().IndexOf("-") >= 0)

{

e.Row.Cells[11].ForeColor = System.Drawing.Color.Red;

}

if (dr.Row[fuzhi].ToString().IndexOf("-") >= 0)

{

e.Row.Cells[12].ForeColor = System.Drawing.Color.Red;

}

if (dr.Row[bilv].ToString().Trim() == "")

{

}

else

{

if (e.Row.Cells[13].Text.IndexOf("-") >= 0)

{

e.Row.Cells[13].ForeColor = System.Drawing.Color.Red;

}

}

num += Convert.ToDouble(dr.Row[bidui]);

numfz += Convert.ToDouble(dr.Row[fuzhi]);

i++;

}

else if (e.Row.RowType == DataControlRowType.Footer)

{

//Label LabelAll = e.Row.FindControl("labelAll") as Label;

//if (LabelAll != null)

//{

// LabelAll.Text += num.ToString();//"计算的总数,或者也可以单独计算";//

//}

e.Row.Cells[0].Text = "共 "+i+"条";

e.Row.Cells[10].Text = "总计:";

e.Row.Cells[11].Text = num.ToString();

e.Row.Cells[12].Text = numfz .ToString();

e.Row.Cells[13].Text = numbil.ToString();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: