日期:2014-05-18 浏览次数:20671 次
DataTable dt = new DataTable(); dt.TableName = "内存表";//获取或设置表的名称 DataColumn datac = new DataColumn(); datac.Caption = "第一列";//获取或设置列的标题 datac.ColumnName = "no1"; DataColumn data2 = new DataColumn(); data2.Caption = "第二列"; data2.ColumnName = "no2"; DataColumn datal = new DataColumn(); datal.Caption = "第三列"; datal.ColumnName = "no3"; DataColumn[] cls=new DataColumn[3]; cls[0] = datac; cls[1] = data2; cls[2] = datal; dt.Columns.AddRange(cls); DataRow row1 = dt.NewRow();//使用该方法来生成行对象 row1[0] = "2000"; row1[1] = "2003"; row1[2] = "6003"; dt.Rows.Add(row1); dt.AcceptChanges();//接受表的修改 this.GridView1.DataSource = dt; this.GridView1.DataBind();
<asp:GridView ID="GridView1" runat="server"> </asp:GridView>