<%@ Page Language="C#"%> <%@ Import Namespace="System.Data"%> <script Language="C#" Runat="Server"> public void Page_Load(Object src,EventArgs e) { int i; DataTable dt=new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("编号")); dt.Columns.ADD(new datacolumn("用户名")); for(i=1;i<8;i++) { dr=dt.NewRow(); dr[0]=Int32.ToString(i); dr[1]="aspcn"+Int32.ToString(i); dt.Rows.Add(dr); } DG1.DataSource = new DataView(dt); DG1.DataBind(); } </script> <html> <head> <title></title> </head> <body> <asp:DataGrid id="DG1" runat=server align=center HeaderStyle-BackColor="#aaaadd"/> </body> </html>