後台創建列,如果前台已經編輯列,則先創建列在html列後,如果試系統自動生成列,則在生成列前。
private void Page_Load(object sender, System.EventArgs e) {
// Put user code to initialize the page here
if(!IsPostBack)
SetBind();
}
}
private void SetBind()
{ SqlConnection conn=new SqlConnection("server=(local);uid=sa;pwd=breakin;database=SDS");
SqlDataAdapter da=new SqlDataAdapter("select * from [Dim.Buyer]",conn);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
// datatable dt=new dataTable() ;
// DataRow tr;
// for(int i=0;i<ds.Tables ["table1"].Columns .Count -1;i++)
// {
// dt.Columns.Add(new DataColumn["c" + i.ToString()]);// }
this.DataGrid1.DataSource=ds.Tables["table1"];
this.DataGrid1.DataBind(); this.DataGrid1 .Columns();
// BoundColumn bc=new BoundColumn() ;
// bc.HeaderText ="test";// bc.DataField ="buyer_code";
// DataGrid1.Columns.Add( bc );
//// BoundColumn bc1=new BoundColumn() ;
// bc1.HeaderText ="test2";
// bc1.DataField ="buyer_code";
// DataGrid1.Columns.Add( bc1 );
this.DataGrid1.DataBind();
}