日期:2014-05-17 浏览次数:20561 次
dt.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("ID1", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID2", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID3", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID4", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID5", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID6", typeof(System.String)));
------解决方案--------------------
完整的例子
<%@ Page Language="C#" EnableViewState="true" AutoEventWireup="true" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("ID1", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID2", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID3", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID4", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID5", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("ID6", typeof(System.DateTime))); for (int i = 1; i <= 6; i++) { BoundField bf = new BoundField(); bf.DataField = "ID" + i; bf.HeaderText = "ID" + i; bf.HtmlEncode = true; System.Data.DataColumn dc = new System.Data.DataColumn(); this.GridView1.Columns.Add(bf); } for (int i = 0; i < 100; i++) { dt.Rows.Add(i, "He" + i.ToString("00"), "He", "Jian", "Bo", new DateTime(2008, 8, 8)); } GridView1.AutoGenerateColumns = false; this.GridView1.DataSource = dt; this.GridView1.DataBind(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>dddd</title> </head> <body> <form id="form1"