在使用GridView时有时会需要多行显示页脚Footer的统计,下面是一种解决方法,仅仅供各位参考
在GridView的RowCreated事件中添加多行页脚,实例代码如下:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == GridViewRowType.Footer)
{
Tuple<int, int> sum = IndexStatisticsDal.GetRecordSum(Convert.ToDateTime(ViewState["StartDate"]), Convert.ToDateTime(ViewState["EndDate"]), StatisticTypeEnum.REENTRYICU);
string resultStr = "⁄";
if (sum.Item2 > )
{
resultStr = ((double)sum.Item1 / sum.Item2 * ).ToString("0.0000") + "‰";
}
TableCellCollection footerRow = e.Row.Cells;
footerRow.Clear();
footerRow.Add(new TableCell());
footerRow[].Text = "合计";
footerRow[].Attributes.Add("rowspan", "");
footerRow.Add(new TableCell());
footerRow[].Text = sum.Item1.ToString();
footerRow.Add(new TableCell());
footerRow[].Text = sum.Item2.ToString() + "</th></tr><tr class=\"C1FooterRow\" style=\"font-size: 14px; font-weight: bold;\">";
footerRow.Add(new TableCell());
footerRow[].Text = "非预期重返重症医学科率";
footerRow.Add(new TableCell());
footerRow[].Text = resultStr;
}
}