private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { DataSet myDS = new DataSet(); DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("列號", typeof(Int32))); dt.Columns.Add(new DataColumn("項目", typeof(string))); dt.Columns.Add(new DataColumn("日期", typeof(DateTime))); dt.Columns.Add(new DataColumn("布爾值", typeof(bool))); for (int i = 1; i <= 9; i++) { dr = dt.NewRow(); dr[0] = i; dr[1] = "Item " + i.ToString(); dr[2] = DateTime.Now; dr[3] = (i % 2 != 0) ? true : false; dt.Rows.Add(dr); } myDS.Tables.Add(dt); DataGrid1.DataSource = myDS; DataGrid1.DataBind(); } }
出處:http://mjgforever.cnblogs.com/