private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { FillData(); } }
#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load);
} #endregion
private void FillData()//绑定DATAGRID { SqlConnection cn=new SqlConnection(str); SqlCommand cmd=new SqlCommand(); cmd.CommandText="SELECT * from UpImage"; cmd.Connection=cn; cn.Open(); SqlDataAdapter da=new SqlDataAdapter(); da.SelectCommand=cmd; DataSet ds=new DataSet(); da.Fill(ds,"Images"); DataGrid1.DataSource=ds.Tables["Images"]; DataGrid1.DataBind(); cn.Close(); } } }
|