在RowDataBound中改变或设置Header和Footer

来源:互联网 发布:电厂环保怎样数据作假 编辑:程序博客网 时间:2024/06/08 16:20
  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
  2.     { 
  3.         if (e.Row.RowType == DataControlRowType.Footer) 
  4.         { 
  5.             e.Row.Cells[0].Text = "21"; 
  6.             e.Row.Cells[1].Text = "All"; 
  7.             e.Row.Cells[2].Text = "Total Dealers Status"; 
  8.             //e.Row.Cells[4].Text = Convert.ToInt32(HidCount.Value).ToString("###,###"); 
  9.             //e.Row.Cells[6].Text = Convert.ToDouble(HidSoldPrice.Value).ToString("C"); 
  10.             e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right; 
  11.            //e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right; 
  12.             //e.Row.Cells[6].HorizontalAlign = HorizontalAlign.Right; 
  13.             //e.Row.Cells[7].Text = DateTime.Now.ToString("yyyy-MM-dd"); 
  14.             //e.Row.Cells[8].Text = DateTime.Now.ToString(@"HH:mm:ss G/MT zzz"); 
  15.         } 
  16.         if (e.Row.RowType == DataControlRowType.DataRow) 
  17.         { 
  18.              
  19.             e.Row.Cells[3].Attributes.Add("style""vnd.ms-excel.numberformat: @"); 
  20.             //e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberformat: @"); 
  21.              
  22.         } 
  23.         if (e.Row.RowType == DataControlRowType.Header) 
  24.         { 
  25.             
  26.             GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.Header, 
  27. DataControlRowState.Normal); 
  28.              
  29.             TableCell cell1 = new TableCell(); 
  30.             cell1.Text = "<b>Report:</b>"; 
  31.             row.Cells.AddAt(0, cell1); 
  32.             TableCell cell2 = new TableCell(); 
  33.             cell2.Text = "New Loans By Deal"; 
  34.             row.Cells.AddAt(1, cell2); 
  35.             TableCell cell3 = new TableCell(); 
  36.             cell3.Attributes["align"] = "right"; 
  37.             cell3.Text = "<font style=/"text-align:right; font-
  38. weight:bold;/">Date/Time:</font>"; 
  39.             row.Cells.AddAt(2, cell3); 
  40.             //TableCell cell4 = new TableCell(); 
  41.             //cell4.Text = DateTime.Now.ToString("yyyy-MM-dd") + " " + 
  42. DateTime.Now.ToString(@"HH:mm:ss"); 
  43.             //row.Cells.AddAt(3, cell4); 
  44.             
  45.             GridView1.Controls[0].Controls.AddAt(0, row); 
  46.         } 
  47.     } 
  48. }
原创粉丝点击