日期:2014-05-18 浏览次数:20473 次
public partial class WebForm7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Chinese", typeof(int));
dt.Columns.Add("Math",typeof(int));
dt.Columns.Add("Nature",typeof(int));
DataRow row = dt.NewRow();
row[0] = 100;
row[1] = 100;
row[2] = 99;
dt.Rows.Add(row);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
Table t = new Table();
if(e.Row.RowType == DataControlRowType.Header)
{
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Text = "Title";
c.ColumnSpan = 3;
c.HorizontalAlign = HorizontalAlign.Center;
r.Cells.Add(c);
TableRow r2 = new TableRow();
TableCell c1 = new TableCell();
c1.Text = e.Row.Cells[0].Text;
r2.Cells.Add(c1);
TableCell c2 = new TableCell();
c2.Text = e.Row.Cells[1].Text;