[csharp]
[csharp]
//創建DataTable
DataTable dt = new DataTable("zhaopian");
//添加列
DataColumn dc1 = new DataColumn("id", Type.GetType("System.String"));
DataColumn dc2 = new DataColumn("wenti", Type.GetType("System.String"));
DataColumn dc3 = new DataColumn("zhaopianming", Type.GetType("System.String"));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
//添加值
DataRow dr = dt.NewRow();
dr[0] = "1";
dr[1] = "測試";
dr[2] = "P123456.jpg";
然後將datatable 賦值給 Gridview
this.dataGrid1.DataSource = dt;