DataTable添加行和列数据
protected void Page_Load() { DataTable newdtb = new DataTable(); newdtb.Columns.Add("Id", typeof(int)); newdtb.Columns.Add("ProName", typeof(string)); newdtb.Columns.Add("ProPrice", typeof(decimal)); newdtb.Columns["Id"].AutoIncrement = true; for (int i = 1; i < 11; i++) { DataRow newRow = newdtb.NewRow(); newRow["ProName"] = "pro" + i.ToString(); newRow["ProPrice"] = 12.3m; newdtb.Rows.Add(newRow); } GridView1.DataSource = newdtb; GridView1.DataBind(); }