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();
}
}
{
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();
}
}
相关文章推荐
- GridView(DataGrid)根据单元格改变单元格颜色简单做法
- 动态改变Gridview单元格的背景颜色
- Gridview的RowDataBound事件(添加删除提示,改变背景颜色)
- aspxGridview 根据单元格值得不同,设置单元格字体的颜色
- Gridview的RowDataBound事件(添加删除提示,改变背景颜色)
- ASPXGridView控件通过列值来改变行的颜色或列的颜色
- ASPxGridview根据条件将符合条件的行颜色改变
- gridview根据条件来改变行的颜色以及改变单元格的颜色。
- ASPxGridview根据条件将符合条件的行颜色改变等
- ASPxGridview根据条件将符合条件的行颜色改变等
- ASPxGridview根据条件将符合条件的行颜色改变等
- ASPxGridView改变列颜色
- ASPxGridview根据条件将符合条件的行颜色改变
- android gridview点击子选项动态改变item背景颜色
- dev gridview 自定义统计行单元格颜色
- win32程序如何改变字体大小颜色
- eclipse改变字体大小和背景颜色
- gridview repeater DataList 鼠标经过改变背景颜色
- gridview 点编辑后显示出来的输入框太大 以致改变了表格整体大小,怎么办?
- python中matplotlib的颜色及线条控制【以及改变legend字体大小】